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

Template's 'new Function' blocked by CSP #906

Closed
bruun opened this issue Dec 18, 2012 · 7 comments
Closed

Template's 'new Function' blocked by CSP #906

bruun opened this issue Dec 18, 2012 · 7 comments

Comments

@bruun
Copy link

bruun commented Dec 18, 2012

The template rendering causes a CSP error, violating the unsafe-eval property: http://www.w3.org/TR/CSP/#script-src

render = new Function(settings.variable || 'obj', '_', source);

This was pointed out, and fixed, in Mustache a few months back: cweider/mustache.js@dac6470

@jdalton
Copy link
Contributor

jdalton commented Dec 18, 2012

The use of the evaluate delimiter makes Function(...) use necessary without making the _.template function too complex. You can always precompile your templates or use Underscore sandboxed.

@jdalton jdalton closed this as completed Dec 18, 2012
@jashkenas
Copy link
Owner

Let's tag 'em as we close 'em ;)

@evert
Copy link

evert commented Jul 30, 2013

Is there any chance at all this could be reconsidered. Some googling reveals a number of people running into this, and it would be brilliant if one of underscore.js's design goals is: runs perfectly in environments where CSP is deployed.

Note that this is not Chrome-specific, this will appear in any CSP-enabled browser.

@jashkenas
Copy link
Owner

Not without us implementing a JavaScript interpreter, I think.

@evert
Copy link

evert commented Jul 30, 2013

That is unfortunate! Thanks for answering though...

@jvoisin
Copy link

jvoisin commented Jun 1, 2017

@jdalton Care to elaborate about how to "precompile your templates"?
I'd like to close this Tor project issue ASAP.
Thank you :)

@jdalton
Copy link
Contributor

jdalton commented Jun 1, 2017

@jvoisin One option is to use lodash-cli. For support on that head over to their gitter chat.

lodash template="./*.jst" settings="{interpolate:/\{\{([sS]+?)\}\}/g}"

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

5 participants