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

[WIP] Fix CSP issue while obtaining ref to global #353

Closed
wants to merge 1 commit into from

Conversation

embiem
Copy link

@embiem embiem commented Dec 19, 2017

Prevent violating Content Security Policy

fixes #335

Prevent violating Content Security Policy

fixes parcel-bundler#335
@embiem
Copy link
Author

embiem commented Dec 19, 2017

It appears that this breaks the globals integration-test, as global: !!global.document evaluates to global: false. I don't really see why, tbh.

I'd love to get a reviewer's eye on this, as the proposed changed in this PR did fix my CSP 'unsafe-eval' issue and the packaged code still worked.

@@ -7,7 +7,7 @@ const VARS = {
asset.addDependency('process');
return 'var process = require("process");';
},
global: () => 'var global = (1,eval)("this");',
global: () => 'var global = typeof global === "object" ? global : typeof window === "object" ? window :typeof self === "object" ? self : this;',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other implementations seem to default to {} instead of this. Trade-offs / concerns with either approach?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In global context this always refers to the global object. As we check before with typeof global === "object" whether the global object exists, it might be a better solution to use {}. I don't feel expert enough to give a definitive answer though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cosmetic nitpick: there's a space missing in :typeof.

@brandon93s brandon93s changed the title Fix CSP issue while obtaining ref to global [WIP] Fix CSP issue while obtaining ref to global Dec 22, 2017
@CvX
Copy link
Contributor

CvX commented Feb 28, 2018

FWIW the tests pass on macOS (node 8.9.3 and 9.6.1) and Linux (node 9.6.1).

@CvX
Copy link
Contributor

CvX commented Mar 1, 2018

@mBeierl You'll also have to replace eval here: src/builtins/hmr-runtime.js:1

@mrcoles
Copy link

mrcoles commented Apr 3, 2018

I’m running into this issue trying to use parcel to build a Chrome extension and all Chrome extensions do not allow 'unsafe-eval'.

@ygnoh
Copy link

ygnoh commented Apr 5, 2018

I'm having the same problem with @mrcoles. I think this problem is very critical.

mrcoles added a commit to mrcoles/parcel that referenced this pull request Apr 8, 2018
merge in this PR parcel-bundler#353 to make some extra changes
mrcoles added a commit to mrcoles/parcel that referenced this pull request Apr 8, 2018
Expands on parcel-bundler#353
Also, prettier updates were auto-applied to hrm-runtime.js.
@infoeon
Copy link

infoeon commented Apr 17, 2018

Can this be replaced with the following instead:

global: () => 'var global = (function(){return this;}).call(null);',

@devongovett
Copy link
Member

Closing in favor of #1133

@devongovett devongovett closed this May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 CSP 'unsafe-eval' not allowed
7 participants