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

underscore.js requires CSP to use 'unsafe-eval' #2995

Closed
BowFarmer opened this issue Apr 14, 2024 · 2 comments
Closed

underscore.js requires CSP to use 'unsafe-eval' #2995

BowFarmer opened this issue Apr 14, 2024 · 2 comments

Comments

@BowFarmer
Copy link

On line 936 there is a call to new Function:

render = new Function(argument, '_', source);

This requires use of 'unsafe-eval' when creating a Content Security Policy for scripts. Would it be possible to change this so 'new Function' is not used?

I don't find underscore.min.js being used on my frontend WordPress, but I do see it included on the admin side of my Wordpress. So when I create the CSP for the admin side, I need to check if the html includes underscore.min.js, and add 'unsafe-eval' to my script CSP.

@jgonggrijp
Copy link
Collaborator

That line is actually line 87 of the template module:

render = new Function(argument, '_', source);

and the trick here is that a template is compiled into JavaScript code. That code can only be executed if you pass it through Function first (or eval, but that would be worse from a security perspective). So no, it cannot be avoided.

I mean, the new is not really necessary here, but the Function is. And I think the Function part is what requires the unsafe-eval directive.

I will close this ticket now because there is nothing we can do, but please feel free to respond if you have any more questions or comments.

@jgonggrijp jgonggrijp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2024
@BowFarmer
Copy link
Author

BowFarmer commented Apr 14, 2024 via email

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

No branches or pull requests

2 participants