Why isn't oSession["x-OverrideGateway"] working?

7 Answers 457 Views
Fiddler Classic
chen
Top achievements
Rank 2
Bronze
Iron
Iron
chen asked on 01 Jul 2023, 05:40 PM | edited on 01 Jul 2023, 07:56 PM

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

Sort by
0
Accepted
Carlos
Top achievements
Rank 2
Iron
answered on 07 Jul 2023, 06:26 PM

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!

0
Nick Iliev
Telerik team
answered on 03 Jul 2023, 11:04 AM

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.

0
chen
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 03 Jul 2023, 05:37 PM

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.

 

To help you understand my situation, I have recorded a video. In the video, you can see the main window of Fiddler in the top left corner, the Fiddler Script editing window in the bottom left corner, and the Edge browser window to its right. The window on far right is the CCproxy SOCKS5 proxy software.
First, I accessed a website, and you can see in the CCproxy window on the right that no traffic passed through. Then, I modified the Fiddler Script , saved it, and accessed the same website again. You can see in the CCproxy window the right that traffic is now passing through.
I hope this recorded video helps you understand my situation.

 


Nick Iliev
Telerik team
commented on 05 Jul 2023, 07:58 AM

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.

chen
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 05 Jul 2023, 01:33 PM

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.

 

0
chen
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 07 Jul 2023, 03:01 AM

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.

 

0
Carlos
Top achievements
Rank 2
Iron
answered on 07 Jul 2023, 12:16 PM

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?

 

Carlos
Top achievements
Rank 2
Iron
commented on 07 Jul 2023, 04:45 PM

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 :-)

0
chen
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 09 Jul 2023, 02:07 AM | edited on 09 Jul 2023, 06:22 AM

@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!

 

Rosen Vladimirov
Telerik team
commented on 10 Jul 2023, 08:47 AM

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).

 

Carlos
Top achievements
Rank 2
Iron
commented on 25 Sep 2023, 12:25 PM

Thanks @Rosen .. a quick question, at the beginning of you comment you say The "x-overrideGateway" flag needs to be set both on the CONNECT tunnel and the actually executed request, does it means if one sets the CONNECT but not the request then the request will be processed by the current instance of Fiddler and not passed upstream either? .. just trying to understand if that is an alternative to the workaround with DIRECT and either of the two can be used and if so which one would be better and why? 
Nick Iliev
Telerik team
commented on 26 Sep 2023, 08:49 AM

Hey Carlos,

The mentioned DIRECT workaround means that the specified sessions will go directly through the upstream proxy and not thought Fiddler.

 

0
Neha
Top achievements
Rank 2
Iron
Iron
answered on 21 Jul 2023, 12:23 PM

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"]);
}


Tags
Fiddler Classic
Asked by
chen
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Carlos
Top achievements
Rank 2
Iron
Nick Iliev
Telerik team
chen
Top achievements
Rank 2
Bronze
Iron
Iron
Neha
Top achievements
Rank 2
Iron
Iron
Share this question
or