-
Notifications
You must be signed in to change notification settings - Fork 4
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
What is the "Origin" in a WebView, for locally hosted content? #7
Comments
Data URLs are generally treated as opaque origins. It's not clear to me how being able to set an origin would ensure that the content is secure, do you mind expanding a bit on that? If possible, it would be appreciated to use the issue template: https://github.com/WebView-CG/usage-and-challenges/blob/main/use_case%26issue_template.md |
I will indeed redo it with the template now that I know it exists... I am not thinking about Data URLs @rayankans - but instead thinking about entire HTML documents (and associated resources - CSS, images, etc.) that are all living locally on a device. For example, an ebook packaged as a EPUB. Or the home screen of a native application (but that uses web tech for some of its UI). |
Following up on this. Locally hosted files are usually loaded as data URLs, so they would still get treated as an opaque origin. Some WebViews also allow you to set the origin in conjunction with that (such as the Android WebView), however I'm still not sure how this "secures" the content. I'd love to hear more about the use case and why something like an EPUB reader would want the ability to set the origin for locally loaded content. |
FWIW, WebViews don't have origins, URLs do. This problem is already solved in Cordova by intercepting HTTP requests on a custom scheme or URL. IIRC, on iOS it uses a custom Perhaps something similar could be standardised some way. |
Do you mean the scheme or URL should be standardized? |
The fact that Android A small background how this works: Androids and iOS' capabilities of hosting code for the webview are also very different.
I hope this clears things a bit up and doesn't go off-topic. Having a standards for the origin of web content hosted by the app for the webview sounds like a good idea. |
We could rename the issue to "What is the origin for locally hosted content?" to make it more clear that this is about the special type of content locally hosted for the webview. |
I can add the perspective from hybrid app developers and framework developers like Apache Cordova and CapacitorJS. If I recall the statistics correctly up to 30% of apps found in the app stores (Apple and Google) are built with frameworks like this. So this is quite a big use case for webviews. Those two frameworks use one big webview for providing app developers a native wrapper and some plugins for their web app. App developers build their web application and put the HTML, CSS and JavaScript files in one folder. The framework then takes care of building a native app project and bundling the web code as a native application ready to distribute via the app stores. App developers usually only need knowledge in HTML, CSS and JavaScript and can call native OS features via plugins. The frameworks provide a bridge that makes these native features available as JavaScript functions inside the webview. Cordova used to host the bundled web content via
Therefore Capacitor and Cordova changed the defaults to hosting the content on their "special origins" mentioned in the comment above. Apps built with this hybrid approach in mind are really dependent on making CORS work and HTTP requests possible on their own web content. This approach might benefit from a standardized way of providing web content from the app to the webview. This content could be considered secure. There are certainly use cases where apps load external content in this "main webview" or mix local content with remote content. For other content like media or ePub we might need to consider more specifics as well. For this discussion we might need to define a definition of how a webview is used.
In case 1 the webview needs to be treated like a browser with all security and privacy considerations in mind. In case 2 the restrictions could be loosened because the webview is just provider of the UI and the risks of the web are already mitigated. The webview acts more like a "normal native application" where those restrictions don't apply. |
That is true in the context of a web app, where the web content is entirely produced/controlled by the creator of the app. However, in the context of an EPUB (or similar technology), where the content is basically UGC (user generated content) completely out of the control of the viewing app - you do need security considerations including CORS...but CORS only works if you have a defined origin to work from (hence this issue). |
It sounds to me like moving from With the With a custom scheme, regardless of whether it's So assuming all WebView content runs on a custom scheme, the only problem left to solve is "should there be the same origin for WebViews across platforms?" To us that's not really an important problem: it doesn't really matter what the origin is, so long as it isn't |
@AshleyScirra are you saying that the work here is only for mobile devices running iOS and Android? WebViews also exist on desktop platforms - whether via platform provided APIs as well as low level solutions like CEF (and stuff in between). Those also need to be considered & evaluated here as well. |
Everything I wrote should apply to any WebView that allows for resource interception, which I think is all of them. As it happens we also have implemented a similar approach for Windows WebView2 on desktop, running on the origin |
You are right that Androids and iOS implementations provided solutions for many problems and solved some of those mentioned. In practice I still encountered some unpleasant because of the different implementations of this. Some of them are:
I speak mostly from my experience on working on an enterprise app with Cordova and an old backend. This captures some use cases and problems I have encountered so far. For some of them there are solutions already with the current state of the WebViews but I wouldn't call them good solutions but more workarounds. Maybe we are looking for a standardized APIs for webviews to load content not found on the web but provided to the webview on a "proper origin". Something like WKURLSchemeHandler or WebViewAsseloader available in every webview in similar ways. I personally like WKURLSchemeHandler and it's capabilities and would like to see it on Android and maybe other platforms as well. So having a standard that describes how developers can bring their content to a special domain for the webview sounds like a great idea to me. iOS approach of using a custom protocol/scheme and allowing the developer to intercept the request content and response of requests to this scheme is really good I think. Androids approach of allowing to overwrite real domain names and giving the developer only limited access to the HTTP request makes less sense to me. But this all is open to discussion and especially security and privacy are interesting considering the different uses of webviews. |
@NiklasMerz Please take a look if PR #25 works for you. |
WebView2 on Windows seems to align most with Android's approach for this case with our |
The security model of the web is based on the concept of an
origin
(see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy for some background), however, in a WebView, especially one pointing to locally hosted content, the origin is unclear/undefined. It is imperative that clients can set the origin to ensure that their content is properly secure.The text was updated successfully, but these errors were encountered: