This is the code I am currently using.
if (oSession.fullUrl.Contains("go_proxy=1"))
{
oSession["ui-backcolor"] = "green";
oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080";
FiddlerObject.log("log:"+oSession["X-OverrideGateway"]);
}
Strangely, when I set the proxy outside the if statement, it works. But when I set the proxy inside the if statement, it doesn't work.
oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080";
if (oSession.fullUrl.Contains("go_proxy=1"))
{
oSession["ui-backcolor"] = "green";
oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080";
FiddlerObject.log("log:"+oSession["X-OverrideGateway"]);
}
I set the session to green in the if code block, and I can see in the log that the code has taken effect. That is, the judgment code is valid, but the proxy setting is invalid.
I don't know why? Please help me, thank you very much!
7 Answers, 1 is accepted
Finally solved!
@chen at all if you still stuck with this one I was able to fix it by overriding the host and then gateway as direct. Now only the specifics requests matching the IF condition only are routed to my upstream gateway for special treatment and all others remain in Fiddler for evaluation.
static function OnBeforeRequest(oSession: Session)
{
if (oSession.uriContains("submit-form"))
{
oSession["x-overrideHost"] = "127.0.0.1:8001";
oSession["x-overrideGateway"] = "DIRECT";
}
}
hope the same works for you.
Cheers!
Hey Chen,
There are several things to consider here:
1. Ensure that you are changing the gateway within the OnBeforeRequest event and not in an event that triggers at a later point.
2. Remove the code related to changing the background color - it is a slow UI operation that might be causing a wanted delay in the execution of the consecutive logic.
3. There is a 302 status indicating that some endpoints are being temporarily moved to another URL. Perhaps, your gateway logic should handle the modified endpoint?
Regards,
Nick Iliev
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Thanks for reply.
First, I confirm that my code is running inside OnBeforeRequest event
Secondly, I have modified my running code to.
if (oSession.fullUrl.Contains("go_proxy=1")) { FiddlerObject.log("before_log:"+oSession["X-OverrideGateway"]); oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; FiddlerObject.log("after_log:"+oSession["X-OverrideGateway"]); }
From the log information, you can see that the judgment statement is effective, but the upstream to the proxy is not effective.
Finally, I have modified the original access and now you can see that the Http status code is 200.
If I use it directly outside the judgment statement, that is, force all visits to go through the upstream proxy, it can effective, which is the most strange place for me.
The code is valid, the judgment code is also effective, but the code pointing to the proxy in the judgment code block is not effective. I hope you can help me solve this problem.
Hey Chen,
In the conditional IF statement, you are checking for oSession.fullUrl. However, the requests proxied through CONNECT Tunnels do not have that information, meaning that a CONNECT request will not know the URL (fullUrl). That means that code won't execute the conditional IF statement for the CONNECT tunnels (which we observed in the video demo), and thus you won't trigger the code related to applying the x-OverrideGateway flag.
Thanks for reply.
According to what you said , the if statement block was not executed.
However, I added logging statements before and after setting x-OverrideGateway , and from the screen recording, it can be seen that the logging statements are effective. Doesn't this prove that the if statement block is valid?
Additionally, I made the following modifications to the statements
//oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; if (oSession.fullUrl.Contains("go_proxy=1")) { FiddlerObject.log("before_log:"+oSession.fullUrl); oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; FiddlerObject.log("after_log:"+oSession["X-OverrideGateway"]); }
From the image, you can see that the fullurl information of the oSession is visible in the log. This proves also that the IF statement block is effective.
Thanks for reply.
According to what you said , the if statement block was not executed.
However, I added logging statements before and after setting x-OverrideGateway , and from the screen recording, it can be seen that the logging statements are effective. Doesn't this prove that the if statement block is valid?
Additionally, I made the following modifications to the statements
//oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; if (oSession.fullUrl.Contains("go_proxy=1")) { FiddlerObject.log("before_log:"+oSession.fullUrl); oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; FiddlerObject.log("after_log:"+oSession["X-OverrideGateway"]); }
From the image, you can see that the fullurl information of the oSession is visible in the log. This proves also that the IF statement block is effective.
I came here looking for help on x-OverrideGateway because it wasn't working for me either and reading here I made some more test and yes I also think something funny somehow with FiddlerClassic at least which is what I'm using. At the end I got it reduced to this more or less:
static function OnBeforeRequest(oSession: Session) {
//oSession["x-overrideGateway"] = "127.0.0.1:1111"; //<=== #1
if (oSession.host == "xxx.xxxx.com") {
//oSession["x-overrideGateway"] = "127.0.0.1:1111"; //<=== #2
if (oSession.uriContains("/urlpart/some-form")) {
oSession["x-overrideGateway"] = "127.0.0.1:1111"; //<==== #3
}
}
}
See the commented line I've added while debugging, if I enable the first commented line (#1), all requests are re-directed to my second Fiddler instance. I should probably say that I'm using 2 different Fiddler Instances running on separate servers, my 1st instance is listening to traffic from clients (iPhone) and I'm interested in passing ONE single specific request to a 2nd instances for some special treatment (see uruContains line).. so again, if I enable the first commented line all requests go to my second instance so I now x-overrideGateway works and my 2 instances can see/decrypt the traffic... then I comment #1 and uncomment #2, now only the traffic for specific domain gets routed, then I comment out #2 and keep #3 only, yes, at first, the specific uri gets re-routed, several times if I keep testing .. it works .. until it doesn't anymore! lol.. let's say I restart my second instances (the one I'm re-routing to), then once the instance is back it no longer re-route the specific request .. only after I enable/disable #1 or #2 it'll begin working again.. very weird because at first I was cracking my head why it wasn't working and what I was doing wrong.. then I read the "if I do it out of the condition" and decided to test it that way.. any clues on why the behavior?
Adding to my testing with most simple scenarios:
Works
static function OnBeforeRequest(oSession: Session)
{
FiddlerObject.log(oSession.url);
oSession["x-overrideGateway"] = "127.0.0.1:8001";
}
This shows in log tab
11:03:42:6462 xxxxx.yyyyy.com/lib/main-page/submit-form
Works (basically same as above)
static function OnBeforeRequest(oSession: Session)
{
FiddlerObject.log(oSession.url);
if (oSession.host.Contains("yyyyy.com"))
oSession["x-overrideGateway"] = "127.0.0.1:8001";
}
this shows in log tab
11:05:29:7363 xxxxx.yyyyy.com/lib/main-page/submit-form
Doesn't work
static function OnBeforeRequest(oSession: Session)
{
FiddlerObject.log(oSession.url);
if (oSession.uriContains("submit-form"))
oSession["x-overrideGateway"] = "127.0.0.1:8001";
}
This shows in the log tab
11:06:38:3928 xxxxx.yyyyy.com/lib/main-page/submit-form 11:06:38:3928 Session #1032 detaching ServerPipe. Had: 'direct->https/xxxxx.yyyyy.com:443' but needs: 'gw:127.0.0.1:8001->https/xxxxx.yyyyy.com:443'
Notice how in this last code I get that extra line in log which doesn't say is an error but seems to be indicating that something is missing? This is beyond my limited knowledge on how HTTPS interception and Gateway works so I'm not sure what to do out of it :-\
Hope someone can help :-)
@Carlos Thanks so such!
Thank you for your response, you have given me another approach to solve the problem.
After testing, the following code is effective.
if (!(oSession.HTTPMethodIs('CONNECT'))&&(oSession.uriContains("go_proxy=1"))) { //oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; //oSession["x-OverrideGateway"] = "192.168.5.201:8080" oSession["x-overrideHost"] = "192.168.5.201:443"; oSession["x-overrideGateway"] = "DIRECT"; }
Although the problem has been solved, the issue with x-overrideGateway not working still exists and needs to be addressed by the developers of Fiddler Classic.
Regardless, thank you for your responses!
Cheers!
Thank you all for the provided information and your steps. The "x-overrideGateway" flag needs to be set both on the CONNECT tunnel and the actually executed request. In your scenarios, the flag is not working for CONNECT requests, as you are checking the path or query parameters. As noted in one of the previous replies - the CONNECT tunnels have only the host. Let's take a look at the example with socks proxy and the check for "go_proxy=1":
//oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080";
if (oSession.fullUrl.Contains("go_proxy=1"))
{
FiddlerObject.log("before_log:"+oSession.fullUrl);
oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080";
FiddlerObject.log("after_log:"+oSession["X-OverrideGateway"]);
}
And from the video we know the go_proxy=1 is a query parameter. For simplicity let's assume the request is https://www.google.com?go_proxy=1.
So, first a CONNECT request is created. The fullURL in this CONNECT is just http://www.google.com:443 This is expected, as the CONNECT request should not have the knowledge for path, query parameters, etc. So, for this request, the code above will not enter the if statement. So, Fiddler will establish a tunnel to google.com without usage of any gateway.
After the CONNECT request, an actual GET request is sent. The fullURL will now contain the query parameter and the request will be executed (and the session in the UI will be marked in green). However, as the connection is already established in the CONNECT tunnel, it does not take into account the gateway.
The suggested workaround with replace of the host and setting the gateway with DIRECT works cause Fiddler does some magic when the host is replaced. You can use the workaround or just set x-overrideGateway for the CONNECT requests as well (which means you'll have to rely on the host information only).
Hey Carlos,
The mentioned DIRECT workaround means that the specified sessions will go directly through the upstream proxy and not thought Fiddler.
In the first part of your code, you're using x-OverrideGateway with a lowercase x, and in the log statement, you're trying to access it using X-OverrideGateway with an uppercase X may souse the Issue.
So Try this.
if (oSession.fullUrl.Contains("go_proxy=1")) { oSession["ui-backcolor"] = "green"; oSession["x-OverrideGateway"] = "socks=192.168.5.201:1080"; FiddlerObject.log("log:" + oSession["x-OverrideGateway"]); }