electron: Electron 9.0.0 webSecurity option no longer disables CORS
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
- Electron Version: 9.0.0
- Operating System: Windows 10 (1904)
- Last Known Working Electron version: 8.2.0
Expected Behavior
Setting BrowserWindow webPreferences: { webSecurity: false } should disable the CORS policy
Actual Behavior
Although I am receiving the electron security warnings for “Disabled webSecurity”,“allowRunningInsecureContent” and “Insecure Content-Security-Policy” in the console I am still getting COR policy errors on my requests.
Here is an example:
Access to XMLHttpRequest at ‘http://localhost:8080/users/login’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 53
- Comments: 34 (6 by maintainers)
Links to this issue
Commits related to this issue
- Disable Web Security in Command Line Summary: We've disabled web security in `BrowserWindow` (https://fburl.com/diffusion/0l0q669m). However, there is a bug in Electron 9 that makes this doesn't work... — committed to facebook/flipper by cekkaewnumchai 4 years ago
- Explicitly disable CORS when running the local dev server This changed in Electron 9. See this issue: https://github.com/electron/electron/issues/23664 — committed to Azure/BatchExplorer by dpwatrous 3 years ago
- Explicitly disable CORS when running the local dev server (#2284) This changed in Electron 9. See this issue: https://github.com/electron/electron/issues/23664 — committed to Azure/BatchExplorer by dpwatrous 3 years ago
I also have this problem. My temporary solution: app.commandLine.appendSwitch(‘disable-features’, ‘OutOfBlinkCors’);
The
webSecurityoption controls the web security inside blink, but recently the control of CORS has been moved out of blink and thus the option no longer controls CORS.I’ll see if there is another way to disable CORS, but it seems that Chromium no longer provides a way to disable CORS per WebContents so we might end up with adding a new session-side option.
I needed both
webSecurity : falseand the command line switch to get rid of CORS errors when using dev-server and trying to accessfile://protocol. But now I need another workaround to solve #23757For me only works if I set
webSecurity: false,andapp.commandLine.appendSwitch('disable-site-isolation-trials')same problem, version 10.1.1
same problem in 9.1.0,
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors');is works to me, but i wish somebody fix it.It seems to me that this was done on purpose. Based on this recommendation: https://www.electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity
This is probably done so that people would not thoughtlessly turn off all policies at once.
The label on this issue shouldn’t be limited to
Platform/Windows. It’s happening for macOS too.Thanks for the link @daltonmenezes 😃 perhaps official docs should list all chrome flags or link and explain those are available options at least.
@zcbenz thank you for the explanation, this makes a lot of sense! Really happy to have some more insight about what’s going on here. Also saw you made a PR, thanks a million!
Sure, but the problem is still that we can’t use it for development purposes. Without it we can’t develop using local backend servers.
Would like to note that this bug does not seem to be platform-specific - we are experiencing this on Linux and macOS in addition to Windows.
The same behavior happens on MacOS. It is not specific to Windows only.
This is also a problem for me (linux)
@daltonmenezes This was reported here: https://github.com/electron/electron/issues/18214 It no longer works for me as of 9.0.0, hence this issue. Does
webSecurity: falsework for you in 9.0.0?@gormonn I don’t think so, or else it would have been documented by the Electron team. That doc has been around for a while, if they were going to remove the API on purpose they would have said something
EDIT: never mind, after some more testing, this has the opposite problem. It seems like
enableBlinkFeatures/disableBlinkFeaturesjust don’t work withOutOfBlinkCors.