Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Proxy support with WKWebView

Is there a way to configure WKWebView to go through a HTTP Proxy server? I know this is possible with NSURLSession directly, but I want to configure it so that all requests through the WKWebView browser go through a proxy.

like image 423
Locksleyu Avatar asked Dec 09 '16 20:12

Locksleyu


People also ask

Is WKWebView deprecated?

Since then, we've recommended that you adopt WKWebView instead of UIWebView and WebView — both of which were formally deprecated. New apps containing these frameworks are no longer accepted by the App Store.

What is a WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

Is WKWebView secure?

The WKWebView is a modern API applying all the modern web security mechanisms, it's still maintained by Apple and gets updates. The good thing about WKWebView is that it does out-of-process rendering, so if the attackers find a memory corruption vulnerability in it, your application's process is still isolated.


1 Answers

NSURLSessionConfiguration has a direct interface(connectionProxyDictionary) to do that , so it can be done easily

But, WkWebView does not have any direct interface like that,it requests ,renders the content out-of-process and so you can imagine like WkWebview instance is sandboxed from the rest of your app

WkWeView even ignores the cookies(NSHTTPCookieStorage), caches(NSURLCache) and Credentials(NSCredentialStorage) of NSURLSession & NSURLConnection likewise these network classes can't access cookies,caches and credentials of WkWebView instance.

The UIWebView does not do it out-of-process and so you can use NSURLProtocol as demonstrated in CustomHTTPProtocol sample to proxy to a server.

As of iOS 10, still there is no support for NSURLProtocol in WkWebView so you can't proxy using WkWebView.

If your proxy server supports tunnelling(VPN) then you can use NetworkExtension.framework and its classes(NEVPNManager, NEVPNProtocol, NEVPNConnection etc..) to direct all the network traffic of your app through your proxy server.

like image 117
Durai Amuthan.H Avatar answered Sep 27 '22 22:09

Durai Amuthan.H