-
Notifications
You must be signed in to change notification settings - Fork 988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proxy requests through WKURLSchemeHandler to bypass Cookies and ITP restrictions #1004
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1004 +/- ##
=======================================
Coverage 74.91% 74.91%
=======================================
Files 13 13
Lines 1718 1718
=======================================
Hits 1287 1287
Misses 431 431 Continue to review full report at Codecov.
|
Do you have any concerns with Apple rejecting apps that essentially "bypass" the WkWebView restrictions they've added? |
I don't have any concerns but I am not entirely sure. We are using this in an app for over a year now without any problems. I think an Apple engineer even suggested this as an possible solution while discussing options how to solve it. Native apps or the xhr plugin just do it like that, too and don't have the restrictions.
|
Hey Niklas I think this is a great addition. Will it also work with sending multipartform data to the backend? [ multipart/form-data ] In my opinion this must be an addition to the ios platform. Maybe there should be a flag or setting to Opt out of the proxy. (If this is not yet foreseen) Another remark is the ability to inspect the HTTP traffic. We are used to inspect it with the network inspector of the browser, but this will not be possible anymore. Kind regards |
Thank you for the feedback
This should work for form data too if you use the special URL. For local stuff you could use
They way it is built now the "proxy" will only work if you convert you URL like
This is no problem somehow. All requests done with the special URLs appear in the inspector as usual.
|
@NiklasMerz Can you please suggest me the steps I should follow to use this PR in my app? |
@razam217 Sure. But you need to be aware that this is work in progress and not part of any release yet. It would be nice if you could test it and give feedback. This PR may have bugs or change in the future. At first you need to remove your iOS platform Good luck! |
Hi @NiklasMerz , I have tried the above mentioned approach in our app and i am able to load the application using cookies.
It would be great if you can help me what i am missing here. |
@NiklasMerz I tested this PR out to see if it would resolve my cookie issues. In safari's network tab, you can click a request. In the headers tab of that request, there are several sections: Summary, Request, Response, and Request Data. When using this branch, the Request Data section seems to be missing, and my endpoint is not receiving the data I've tried to attach to the request. If it helps, I'm using Angular 10.1.3's HttpClient to generate the request. If you have any ideas or need more information from me please let me know. Thanks! |
From my experience request data is always there for post requests done with fetch. Any ideas what is different? |
It looks like the issue is only present in iOS 12 or iOS11 (I hadn't realized I hadn't updated yet). I don't see it in iOS 13 or iOS 14. Not sure if you intend to support <13, but it looks like [email protected] supports 11 or later. A couple other things that should be considered:
Thanks! Edit: Your comment above mentions |
I found one more thing: it doesn't look like this works for iframes. An iframe that's hosted by the same remote that I'm authenticated with does not seem to have access to authentication cookies. Thanks again. |
New PR #1030 is the new path forward. cordova-ios will just allow plugins to plug into the WKURLSchemeHandler. The proxy is done in a plugin. |
@NiklasMerz Thanks for the WKURLSchemeHandler implementation. I took #1030 PR and integrated with your plugin https://github.com/GEDYSIntraWare/cordova-plugin-webview-proxy. Also changed the URL per your suggestion. All my XHR calls are now directed to webiewproxy.m and completes with proper response. However, in my case my API responds with a few session cookies and I don't see them getting synced to my Cordova main web view. I see cookies in native cookie store but not in Cordova main web view. Is this expected ? Any solution to this? I have a Single Sign On implementation which needs these session cookies to be sent along with http GET URL request (window.location = url to a subdomain) to a my own server. But the request is sent without cookies and hence it fails. I tried by configuring CDVWebViewEngine's webdatastore to a nonPersistant one and added cookies to the same store as in below, but that didn't sync cookie to Cordova Main webview first added app bound domain in the info.plist and then in CDWebViewEngine:77. if (@available(iOS 14.0, *)) {
and in webviewproxy.m:40
Any idea if cookies are not meant for syncing or am I missing something ? I am testing in iOS14 with XCode 12.3. |
Platforms affected
iOS
Motivation and Context
iOS became more restrictive for CORS and tracking prevention which makes it hard for some apps to communicate with their server and use cookies.
See #922 #605 and possibly many more
Description
This PR implements a kind of "proxy" that takes requests like the normal webview and runs them through native code to make the request work without the CORS restrictions. Cookies are synced with the webview.
Originally taken from a modification in Ionics webview: ionic-team/cordova-plugin-ionic-webview#448
TODO
Testing
In a sample app for now. Use this code snippet to run code through the proxy:
fetch(window.WkWebView.convertProxyUrl("https://cordova.apache.org"));
Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)