wails icon indicating copy to clipboard operation
wails copied to clipboard

Disable the Webview2 security policy

Open jinpy666 opened this issue 2 years ago • 17 comments

Is your feature request related to a problem? Please describe.

For some crawlers, multi-account management of web projects is very meaningful ~ hope to support. Thank you so much for your team's work.

Describe the solution you'd like

CORS requests need to be supported. Read and write cookies and storages of any site.

Describe alternatives you've considered

No response

Additional context

No response

jinpy666 avatar Jun 29 '22 13:06 jinpy666

You can follow this issue.

https://github.com/MicrosoftEdge/WebView2Feedback/issues/2558

misitebao avatar Jul 01 '22 08:07 misitebao

Hi, you can use the --disable-web-security, browser flag (at your own risk since this disables security policies such as cross origin restrictions :) ) to achieve what you are looking for. You can set additional browser arguments to WebView2 via CoreWebView2EnvironmentOptions. We don't intend to provide an API for this at the moment due to security risks involved. Hope this helps!

yildirimcagri-msft avatar Jul 01 '22 20:07 yildirimcagri-msft

Thank you~ @yildirimcagri @misitebao

jinpy666 avatar Jul 02 '22 03:07 jinpy666

This would answer my #1375 as well, but I am still not sure how do you put flag --disable-web-security in wails?

KiddoV avatar Aug 02 '22 00:08 KiddoV

Yeah, we could look at just adding a passthrough string to the options. I haven't really had a chance to consider the implications though

leaanthony avatar Aug 02 '22 07:08 leaanthony

The CORS policy really is a pain since reading local files is a common use-case for desktop apps and 'proxying' them via the asset handler is not always feasible and presents a security risk if not properly implemented. I hope this issue is resolved soon.

Qendolin avatar Sep 07 '22 13:09 Qendolin

It's scheduled. If you want to raise a PR sooner, feel free 👍

leaanthony avatar Sep 07 '22 13:09 leaanthony

  os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-web-security")

fynxiu avatar Nov 01 '22 08:11 fynxiu

  os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--disable-web-security")

That won't work anymore since PR #1771 has been merged and will also not work with new native go-webview2loader (currently experimental) merged with PR #1974.

stffabi avatar Nov 01 '22 09:11 stffabi

Yeah we plan on supporting this in a better way @fynxiu

leaanthony avatar Nov 01 '22 10:11 leaanthony

Yeah supporting this is now pretty straight forward with the new go-webview2loader.

From a personal view I'm still not 100% sure if this should be supported right out of the box. Because that easily opens an app for several security problems if one doesn't take care what will be loaded into the frontend.

stffabi avatar Nov 01 '22 10:11 stffabi

It's scheduled. If you want to raise a PR sooner, feel free 👍

Hi @leaanthony , sorry for replying an old issue, but may I know what's the last status of this enhancement? I see someone opened a PR #2476 couple months ago, but haven't got finalized yet until now.

I really need this feature to use Wails any further, and I'm willing to help to create a PR if it is still "relevant" (since this feature should be included in 2.3 milestone, but somehow ignored).

haranobuhardo avatar Oct 24 '23 07:10 haranobuhardo

Yeah, I think this is the wrong way to go about it. The correct way would be to use middleware to make the requests for you and ignore the TLS certificates in Go. That way it'll work on all platforms and we don't relax the webview security policy.

leaanthony avatar Oct 24 '23 09:10 leaanthony

Yeah, I think this is the wrong way to go about it. The correct way would be to use middleware to make the requests for you and ignore the TLS certificates in Go. That way it'll work on all platforms and we don't relax the webview security policy.

So, it's like creating a universal CORS middleware and keep the middleware running as long as the user need the feature to bypass the CORS. Correct?

haranobuhardo avatar Oct 25 '23 01:10 haranobuhardo

It's not just about CORS but in general I'd choose to deal with remote resources in Go. You can lock it down better.

leaanthony avatar Oct 25 '23 08:10 leaanthony