Proxy localhost/loopback requests through configured proxy

Hello,

I want to proxy localhost/127.0.0.1 network requests through the configured proxy. All requests are working fine and get proxied through except the localhost/127.0.0.1 requests. I found kCFStreamPropertyProxyLocalBypass which I can use and seems right, but it doesn't work when setting it to false.

Is this a CFNetwork/mac limitation? Since I could not find anything in the internet that this is actually possible.

I'm setting it via the connectionProxyDictionary.

OK, I’d like to confirm some context here:

  • What API are you using? It sounds like you’re using NSURLSession, but please confirm.

  • Within NSURLSession, what type of tasks are you concerned with? HTTP tasks (data, download, upload)? Stream tasks? Or WebSocket tasks?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi, thanks for your answer! I'm working on WebKit, so we are using NSURLSession see here. Probably a data task for visiting websites, but I can confirm it with my local build.

so we are using NSURLSession

OK. The connectionProxyDictionary property should accept any of the kSCPropNetProxiesXXX properties defined in <SystemConfiguration/SCSchemaDefinitions.h>. Some things to note here:

  • <SystemConfiguration/SCSchemaDefinitions.h> is only in the macOS SDK. The definitions apply across all platforms but not all platforms support all proxy types.

  • Many of these properties have aliases in higher-level headers, like <CFNetwork/CFSocketStream.h> and <CFNetwork/CFHTTPStream.h>.

  • Many of those are deprecated )-:

We have a bug on file to sort out this confusion (r. 19821165).

Anyway, the upshot of the above is that I tend to use the SC keys when discussing this. And in that context kSCPropNetProxiesExcludeSimpleHostnames is the droid you’re looking for. Does that not work? Can you post a snippet of how you tried setting it up?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Regarding the platform, only macOS is in the scope for this request. Is this bug report publicly visible in some bug tracker?

I tried to use kSCPropNetProxiesExcludeSimpleHostnames but I get use of undeclared identifier. Is it internally different to kCFNetworkProxiesExcludeSimpleHostnames?

Regarding the snippet, I tried the following:

[dictionary setObject:[NSNumber numberWithInteger:0] forKey:(NSString *)kCFNetworkProxiesExcludeSimpleHostnames]

Maybe I understand it not correctly and 0 as a number is incorrect. I also tried various combinations out of kCFStreamPropertyProxyLocalBypass and kCFNetworkProxiesExcludeSimpleHostnames with booleans and integers.

I will try to come up with a small reproducible to test it without the whole WebKit project.

Is this bug report publicly visible in some bug tracker?

No, alas.

I tried to use kSCPropNetProxiesExcludeSimpleHostnames but I get use of undeclared identifier.

You would need to import the System Configuration framework.

Is it internally different to kCFNetworkProxiesExcludeSimpleHostnames?

No. If you print these constants they all have the same value. For example, all three of these:

print(kCFNetworkProxiesExcludeSimpleHostnames)
print(kSCPropNetProxiesExcludeSimpleHostnames)
print(kCFStreamPropertyProxyLocalBypass)

print ExcludeSimpleHostnames.

I will try to come up with a small reproducible to test it

Ta.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I created a small GitHub repository with the reproducible to demonstrate it: https://github.com/mxschmitt/cfnetwork-localhost-proxy

Thank you for your help!

@DTS Engineer are there updates on this by any chance? Since this is still blocking us. Thank you!

Proxy localhost/loopback requests through configured proxy
 
 
Q