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

"SharedArrayBuffer will require cross-origin isolation" with the dev server #6220

Closed
mischnic opened this issue May 2, 2021 · 9 comments · Fixed by #6404
Closed

"SharedArrayBuffer will require cross-origin isolation" with the dev server #6220

mischnic opened this issue May 2, 2021 · 9 comments · Fixed by #6404

Comments

@mischnic
Copy link
Member

mischnic commented May 2, 2021

🐛 bug report

Using SharedArrayBuffer will require/already requires setting some headers on the server:

https://developer.chrome.com/blog/enabling-shared-array-buffer/

💁 Solution

We already set the "normal" CORS headers:

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Methods',
'GET, HEAD, PUT, PATCH, POST, DELETE',
);
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept, Content-Type',
);

The dev server should set the headers described on the linked Chrome page, probably these:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin

The question is whether we can just always set them or if this can cause problems

🌍 Your Environment

Software Version(s)
Parcel v2
@LironHazan
Copy link
Contributor

@mischnic

Hey 👋

I wanted to take a look but regardless to the issue itself, running "yarn build" for the simple example is routing to the 404 page, is it something known?

So I added the following block into the setHeaders()

  res.setHeader('Cross-origin-Opener-Policy', 'same-origin');
  res.setHeader('Cross-Origin-Resource-Policy', 'same-origin');
  res.setHeader('Cross-Origin-Embedded-Policy', 'require-corp');

Verified that all tests are passing, and started "react-refresh" example instead,
it seem to work ok with or without the new headers,
I updated the react@latest react-dom@latest in order to avoid the "SharedArrayyBuffer" deprecation warning (a bug in version 16)

Updating the react dependencies also tweaked the parcel-create-react-app and the core/parcel package.json bin location from src/bin.js to lib/bin.js, I'm not sure why actually, maybe you'll know?

LMK what is the right way of testing the headers additions?

Thanks!

@mischnic
Copy link
Member Author

running "yarn build" for the simple example is routing to the 404 page, is it something known?

That's probably because there's no HTML file in https://github.com/parcel-bundler/parcel/tree/v2/packages/examples/simple.

Updating the react dependencies also tweaked the parcel-create-react-app and the core/parcel package.json bin location from src/bin.js to lib/bin.js, I'm not sure why actually, maybe you'll know?

That only happens after running yarn build. You need to revert that change.

LMK what is the right way of testing the headers additions?

Our existing dev server integration tests are here: https://github.com/parcel-bundler/parcel/blob/v2/packages/core/integration-tests/test/server.js

@valentinbdv
Copy link

Hello, these headers will prevent loading external script with parcel:
Screenshot 2021-07-01 at 01 39 27
Is there a way to choose if we want to include them or not?

Thanks a lot for your help, Valentin

@LironHazan
Copy link
Contributor

LironHazan commented Jul 1, 2021

@valentinbdv can you try using the crossorigin attribute as follows?
<img src="https://third-party.example.com/image.jpg" crossorigin>
read more here (I didn't tested btw, I'm not sure that will work)
(@mischnic worth documenting)

@mischnic
Copy link
Member Author

mischnic commented Jul 1, 2021

I think what #6499 describes would fix this for you

@valentinbdv
Copy link

Thanks for your answers!

@LironHazan, I confirm that the cross-origin attribute fixes the issue as I used it already.
But in this case, I am loading a script that is itself loading another script so I can't add the attribute.

@mischnic I also tried to use proxyrc but then I guess I had the same issue as the one you linked. Do you know when the fix will be available?

@mischnic
Copy link
Member Author

mischnic commented Jul 2, 2021

That bug is fixed already in the latest nightly

@valentinbdv
Copy link

I confirm this is working! Thanks a lot ;)

@bminer
Copy link

bminer commented Jul 23, 2021

Just continuing the above discussion, you can disable COEP by creating .proxyrc.js with the following:

module.exports = function(app) {
  app.use((req, res, next) => {
    res.setHeader('Cross-Origin-Embedder-Policy', 'unsafe-none')
    next()
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants