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

CSP - unsafe-eval errors because of "new Function" #265

Closed
thyngster opened this issue Mar 4, 2024 · 4 comments · Fixed by #268
Closed

CSP - unsafe-eval errors because of "new Function" #265

thyngster opened this issue Mar 4, 2024 · 4 comments · Fixed by #268
Labels
browser extension scope: browser extension bug Something isn't working

Comments

@thyngster
Copy link

I'm working on a browser extension, and I wanted to used vue-devtools. But since MV3, CSP unsafe-eval is enforced, meaning that yuou cannot use:

  • eval()
  • Function()
  • setTimeout() with an initial argument which is not callable.
  • setInterval() with an initial argument which is not callable.

according to: https://www.w3.org/TR/CSP3/#directive-script-src

Leading to the following error:
(index):71 Uncaught (in promise) EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' http://localhost:3303 http://localhost:8098".

I used to have the old devtools working.

It seems that this as explicitly allowed at some point. ( looking at the eslint config ) :

const action = new Function('devtools', '...args', `return (${payload.action})(devtools, ...args)`)

@webfansplz webfansplz added bug Something isn't working browser extension scope: browser extension labels Mar 4, 2024
@webfansplz
Copy link
Member

Thank you for the feedback, you can downgrade to v7.0.15. I'll check it out later.

@thyngster
Copy link
Author

I re-reading my report and It was not 100% clear, with previous versions I mean 6.x ones. It's my first time trying to use 7.x on this environment.

I expect the issue can a bit complex to fix since it implies rewriting the new Function() parts, which may not be an option at some point.

@webfansplz
Copy link
Member

I re-reading my report and It was not 100% clear, with previous versions I mean 6.x ones. It's my first time trying to use 7.x on this environment.

I expect the issue can a bit complex to fix since it implies rewriting the new Function() parts, which may not be an option at some point.

I know, the code of new Function parts shipped on V7.0.16 (so v7.0.15 should be work fine.), we try use it to refactor the bridge messaging, now seems we missed this use cases, we’ll revert the design to cover this use case.

@thyngster
Copy link
Author

thyngster commented Mar 4, 2024

ok, you're right. I reinstalled vue-devtools 7.0.15 globally and for some reason was still picking the old js build.

I can confirm that after checking on 7.0.15 and compiling it works just fine.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser extension scope: browser extension bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants