Skip to content
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

[4.0.0-beta.3] webSecurity in webPreferences ignored (CORB) #15132

Closed
ghost opened this issue Oct 13, 2018 · 21 comments
Closed

[4.0.0-beta.3] webSecurity in webPreferences ignored (CORB) #15132

ghost opened this issue Oct 13, 2018 · 21 comments
Labels
4-2-x bug 🪲 bug/regression ↩️ A new version of Electron broke something status/reviewed A maintainer made an initial review but not reproduced the issue

Comments

@ghost
Copy link

ghost commented Oct 13, 2018

  • Output of node_modules/.bin/electron --version: v4.0.0-beta.3
  • Operating System (Platform and Version): Windows 10
  • Output of node_modules/.bin/electron --version on last known working Electron version (if applicable): v3.0.4

Expected Behavior
With electron 3, I could pass webPreferences: {webwebSecurity: false} to the BrowserWindow constructor (the equivalent of the --disable-web-security Chrome command line argument) which would disable CORB (effectively allowing cross-origin requests).

Actual behavior
CORB is still doing its thing (ignoring the {webwebSecurity: false} option; I see entries like these in the console:
Cross-Origin Read Blocking (CORB) blocked cross-origin response <URL> with MIME type application/json. See <URL> for more details.

To Reproduce
Make a request (using fetch or xhr) to a file on a different domain.
Example repo:

git clone  https://github.com/IAmPicard/electron-cors-repro
npm install
npm run start
@ghost ghost changed the title [4.0.0-beta.3] webSecurity in webPreferences ignored [4.0.0-beta.3] webSecurity in webPreferences ignored (CORS) Oct 13, 2018
@MarshallOfSound MarshallOfSound added bug 🪲 status/reviewed A maintainer made an initial review but not reproduced the issue 4-2-x labels Oct 13, 2018
@blackknifes
Copy link

@MarshallOfSound
The bug also is exists on version 3.x.

@MarshallOfSound
Copy link
Member

@blackknifes That directly contradicts the statement made in the original issue

With electron 3, I could pass webPreferences: {webwebSecurity: false} to the BrowserWindow constructor (the equivalent of the --disable-web-security Chrome command line argument) which would disable CORB (effectively allowing cross-origin requests).

@IAmPicard Can you confirm v3 works as expected?

@ghost
Copy link
Author

ghost commented Oct 14, 2018

Yes, everything worked as expected ever since I started using it (back in the 1.8 days) up-to the latest available 3.0 (3.0.4).

@nornagon
Copy link
Member

Is it possible you could put together a small repro case (perhaps with https://github.com/electron/fiddle)? I'm not sure exactly how to trigger CORB and I'd like to make sure I'm testing exactly what you're seeing.

@blackknifes
Copy link

@IAmPicard
When I started with vue + vuex + webpack + webpack-hot-middleware, It throw cors error.Of course,I have setted webSecurity to false.

@ghost
Copy link
Author

ghost commented Oct 16, 2018

I uploaded a small repro case here: https://github.com/IAmPicard/electron-cors-repro.

I tried electron-fiddle, but it looks like the issue doesn't repro when using the "file://" protocol, it needs a local server (http://localhost) such as webpack-dev-server to repro.

If you run the repro as-is, the app will load without errors; after you upgrade the electron from 3.0.4 to 4.0.0-beta.3, the app will error out with CORB.

@blackknifes
Copy link

t
t
t

@IAmPicard
The project worked as expected on version v2.x, but throw errro on version v3.x.
Why it throw error on version v3.x?

@ghost
Copy link
Author

ghost commented Oct 16, 2018

@blackknifes I don't believe your issue is related to CORS, it's most likely same-origin, and unrelated to the issue described here (which is CORS-related, and specific to 4.0.0).

@blackknifes
Copy link

@IAmPicard Ok, I will create new issue.

@nornagon nornagon added bug/regression ↩️ A new version of Electron broke something and removed blocked/needs-repro labels Oct 16, 2018
@nornagon
Copy link
Member

Confirmed, that repro case behaves differently on 3.0.4 and 4.0.0-beta3.

@aokihu
Copy link

aokihu commented Oct 20, 2018

I have met the same problem, upgrade from 3.0.5 to 4.0-beta, It's good at 3.0.5
My platform is macOS
screen shot 2018-10-20 at 2 57 17 pm

@BinaryMuse BinaryMuse self-assigned this Oct 25, 2018
@BinaryMuse
Copy link
Contributor

BinaryMuse commented Oct 26, 2018

It looks like CrossOriginReadBlocking::ResponseAnalyzer::ShouldAllow() is returning false here due to should_block_based_on_headers_ being set to kBlock.

We were unable in the time we had today to determine if there was a way to affect this behavior based on the webSecurity option; however, on master, Chromium includes this code in CrossSiteDocumentResourceHandler::ShouldBlockBasedOnHeaders (which is what creates and uses the ResponseAnalyzer):

  // --disable-web-security also disables Cross-Origin Read Blocking (CORB).
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kDisableWebSecurity))
    return false;

Unclear to me if this is the best way forward, however passing --disable-web-security on Electron built from master after including the above snippet does seem to resolve this issue.

@MarshallOfSound MarshallOfSound changed the title [4.0.0-beta.3] webSecurity in webPreferences ignored (CORS) [4.0.0-beta.3] webSecurity in webPreferences ignored (CORB) Nov 6, 2018
@BinaryMuse
Copy link
Contributor

After chatting with @deepak1556, #15618 should allow us to tackle this in a good way.

@BinaryMuse BinaryMuse removed their assignment Nov 7, 2018
@aokihu
Copy link

aokihu commented Nov 13, 2018

Do you fix the problem now? I test beta5, and it does not work well

@aokihu
Copy link

aokihu commented Nov 14, 2018

If the problem can not be fixed, the project is useless from 4.0
An isolate application can not in the same URL domain, so how we communicate with server?

@deepak1556
Copy link
Member

Although the issue is fixed in #15737 , I would suggest not to disable web security in production. Here are some good docs about CORB checks and how to fix it in your application, from the chrome team https://developers.google.com/web/updates/2018/07/site-isolation

For in-depth understanding of CORB https://chromium.googlesource.com/chromium/src/+/master/services/network/cross_origin_read_blocking_explainer.md

@ghost
Copy link
Author

ghost commented Nov 16, 2018

Although the issue is fixed in #15737 , I would suggest not to disable web security in production.

The alternatives are to allow all origins on the server (Access-Control-Allow-Origin: *), or to move all such network calls down into node and IPC all the data, right?

Or am I missing another alternative that allows us to do fetch() calls from origin file:// against a CORS-enabled server (that doesn't allow file:// for obvious reasons)? Perhaps a way to modify the (otherwise unmodifiable) origin header on requests?

@deepak1556
Copy link
Member

to move all such network calls down into node

You can use the net module along with stream protocol

Or am I missing another alternative that allows us to do fetch() calls from origin file:// against a CORS-enabled server

Yeah I would advice against relying on file for these scenarios

@ckerr
Copy link
Member

ckerr commented Nov 21, 2018

Still needs to be backported to 4-0-x

@ckerr ckerr reopened this Nov 21, 2018
@ghost
Copy link
Author

ghost commented Dec 1, 2018

I can confirm the issue is fixed in v4.0.0-beta.8 ; I'm experiencing other unrelated crashes with v4.0.0-beta.8, but this particular regression no longer repros.

Thank you!

@deepak1556
Copy link
Member

@IAmPicard thanks for confirming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4-2-x bug 🪲 bug/regression ↩️ A new version of Electron broke something status/reviewed A maintainer made an initial review but not reproduced the issue
Projects
None yet
Development

No branches or pull requests

7 participants