fiddler: how to disable overwrite Header Host

2020-02-10 04:38发布

When using Fiddler, it pops up an alert dialog.

Fiddler has detected a protocol violation in session #14.

The Request's Host header did not match the URL's host component.

URL Host:   proxy.music.pp.com
Header Host:    119.147.22.41

And it shows that Fiddler changed HTTP Header's host to "proxy.music.pp.com", is there any way to disable Fiddler changing it?

4条回答
狗以群分
2楼-- · 2020-02-10 05:20

You can do this with rules.

Go into Customize rules, and find the function: OnBeforeRequest(oSession: Session)

Then add the following as the last line of that function:

if (oSession.HostnameIs("proxy.music.pp.com")) { oSession.host = "119.147.22.41"; }
查看更多
beautiful°
3楼-- · 2020-02-10 05:25

I couldn't get what I needed for the existing answers, but Eric Law's answer gave me what I needed to fix my issue. I was having a problem where I was calling a web server by IP address, and I had to add a Host header to get the right endpoint. Fiddler was changing the Host header to the IP address I was calling and removing my Host header value, which caused the call to fail. I added a line to Eric's script to solve this. I put the rule into OnBeforeRequest in the Fiddler Rules Script.

 if (oSession.BitFlags & SessionFlags.ProtocolViolationInRequest) 
    {
        var sOverride = oSession["X-Original-Host"];

        if (!String.IsNullOrEmpty(sOverride)) 
        {
            oSession["X-overrideHost"] = sOverride;
            oSession["ui-backcolor"] = "yellow";
            oSession.oRequest["Host"] = sOverride;

            // Be sure to bypass the gateway, otherwise overrideHost doesn't work
            oSession.bypassGateway = true;
        }
    }

Took this Error:
404 error Bad Request

And changed it to this: 200 Response Good Request

查看更多
家丑人穷心不美
4楼-- · 2020-02-10 05:37

I didn't understand what the "url host" was supposed to be - I mean, normally, there is only the Host header in HTTP.

Looking closer, it appears that this violation occurs for an initial proxy "setup" request, which looks like this:

 CONNECT targaryen:45633 HTTP/1.1
 Host: targaryen

This is where the error makes sense to me.

查看更多
smile是对你的礼貌
5楼-- · 2020-02-10 05:39

From my book:

Swap the Host Header

When Fiddler gets a request whose URL doesn’t match its Host header, the original Host value is stored in the session flag X-Original-Host and then the Host value is replaced with the host parsed from the URL. The following script, placed inside your FiddlerScript's BeforeRequest function, reverses behavior by routing the request to the host specified by the original Host header.

if (oSession.BitFlags & SessionFlags.ProtocolViolationInRequest) 
{
  var sOverride = oSession["X-Original-Host"];
  if (!String.IsNullOrEmpty(sOverride)) 
  {
    oSession["X-overrideHost"] = sOverride;
    oSession["ui-backcolor"] = "yellow";

    // Be sure to bypass the gateway, otherwise overrideHost doesn't work
    oSession.bypassGateway = true;
  }
}
查看更多
登录 后发表回答