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

FEAT: Support Content-Security-Policy #3558

Closed
aimeos opened this issue Jun 22, 2021 · 7 comments · Fixed by #3677
Closed

FEAT: Support Content-Security-Policy #3558

aimeos opened this issue Jun 22, 2021 · 7 comments · Fixed by #3677

Comments

@aimeos
Copy link

aimeos commented Jun 22, 2021

To reduce the possible attack surface if the editor is used in "hostile" environments (e.g. in SaaS platforms) support for CSP is required. This will also prevent problems like #3082

At the moment, the only problem that prevents effective CSP rules is the use of new Function() in the GrapesJS code, which requires a CSP rule of unsafe-eval.

Is there a different way to implement that?

@artf
Copy link
Member

artf commented Jun 24, 2021

mmm I'm not sure exactly how I'm able to fix it and what do you mean by is the use of new Function() in the GrapesJS code as there is no such a thing in the source?

@aimeos
Copy link
Author

aimeos commented Jun 24, 2021

Found out that it's in the dist files due to underscore.js template() method which uses new Function(). I think this will make it hard to replace or remove that dependency to enforce a CSP without 'unsafe-eval'.

@ronaldohoch
Copy link

Maybe this can be changed by using it: https://github.com/silvermine/undertemplate
Find it looking into this issue in underscore repo: jashkenas/underscore#2273

Can you share your CSP config to test it?

@aimeos
Copy link
Author

aimeos commented Jul 9, 2021

<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data:">

@artf
Copy link
Member

artf commented Aug 5, 2021

@aimeos I'm wondering how the detection is performed. If it's based on execution it's not a big deal to replace all references of the template function (at least not if there is a security concern)

@aimeos
Copy link
Author

aimeos commented Aug 5, 2021

@artf Guess, browsers block certain dynamic function declarations (new Function('<string>')) and function calls / language constructs (e.g. eval) when CSP is activated.

@artf
Copy link
Member

artf commented Aug 5, 2021

ok then, I'll try to fix it for the next release.

@artf artf closed this as completed in #3677 Aug 5, 2021
artf added a commit that referenced this issue Aug 5, 2021
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.

3 participants