VPN or proxy connection only between app and server macOS

Hi. I am creating an app for macOS, my app have WKWebView and I need to send traffic through a VPN server or proxy if the website is blocked, I know that I can't set proxy for WKWebView only one way which I see It is to create VPN Connection for the whole system, but this way doesn't look good for me.
My question how I can create VPN or proxy connection only between the app and server, not for the whole system only for the app, this is possible?
If yes give me please advice on how to do that, what I can use.
Thank you.

Regards, Ihor.
Answered by Systems Engineer in 665031022

My question how I can create VPN or proxy connection only between the app and server, not for the whole system only for the app, this is possible?

Blocking network traffic for unwanted sites is by definition a content filter action. So, you could look at NEFilterDataProvider as a first option. This would allow you to inspect the bundle id the traffic is coming from (your WKWebView app) and then attempt to inspect the remote address the network request is trying to connect to to make a decision.

Next, for proxying traffic directly in WKWebView, there is not support for this functionality. This would be a great enhancement request. You would have to move the proxy functionality out to the system level and either create an NEAppProxyProvider, or use the System Configuration proxy settings to route traffic locally to a process so it can decide where the traffic needs to go. Both are a lot of work and do seem like a bit of overkill for this action. I would try looking into NEFilterDataProvider as a first step here.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer

My question how I can create VPN or proxy connection only between the app and server, not for the whole system only for the app, this is possible?

Blocking network traffic for unwanted sites is by definition a content filter action. So, you could look at NEFilterDataProvider as a first option. This would allow you to inspect the bundle id the traffic is coming from (your WKWebView app) and then attempt to inspect the remote address the network request is trying to connect to to make a decision.

Next, for proxying traffic directly in WKWebView, there is not support for this functionality. This would be a great enhancement request. You would have to move the proxy functionality out to the system level and either create an NEAppProxyProvider, or use the System Configuration proxy settings to route traffic locally to a process so it can decide where the traffic needs to go. Both are a lot of work and do seem like a bit of overkill for this action. I would try looking into NEFilterDataProvider as a first step here.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
VPN or proxy connection only between app and server macOS
 
 
Q