"eval" in 2.6.3 requires the use of an unsafe-eval CSP directive
See original GitHub issueFirst of all, thank you for your solution which is really great and quite incredible in terms of performance!
Feature request
Remove the use of eval
(found in …Function("return this")()||(0,eval)("this")…
in https://cdn.jsdelivr.net/npm/instantsearch.js@2.6.3) so that we could use a script-src
directive in our Content Securities Policies that would not be forced to unsafe-eval
.
Use case
I have a pretty restrictive CSP on borisschapira.com and don’t want to authorize all my third-party domains to execute eval
in order to authorize Algolia Instant Search on my search page.
work to fix this (added by @haroenv)
remove or fork Hogan.js to remove the lines using new Function
. I think this might be quite hard, since AFAICT, it’s what allows {{{
. We could enforce template strings maybe however 🤔
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:19 (13 by maintainers)
Top Results From Across the Web
Content Security Policy Level 3 - W3C
The 'unsafe-hashes' source expression will now allow event handlers, style attributes and javascript: navigation targets to match hashes.
Read more >An Unsafe Content Security Policy (CSP) Directive in Use
A An Unsafe Content Security Policy (CSP) Directive in Use is an attack that is similar to a Code Execution via File Upload...
Read more >ngCsp - AngularJS: API
Overview ; no-unsafe-eval tells AngularJS that we must not use eval, but that we can inject inline styles. E.g. ; <body ng-csp="no-unsafe-eval"> ....
Read more >How To Secure Node.js Applications with a Content Security ...
A CSP is an HTTP header that provides an extra layer of security against ... To use this directive, you need to add...
Read more >Content Security Policy - WSTG - Latest | OWASP Foundation
unsafe -eval directive allows eval() to be used in the application. unsafe-hashes directive allows use of inline scripts/styles, assuming they match the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to be clear for future readers (or ourselves in several months), changing the CSP to accept the
eval
would mean addingunsafe-eval
. In most cases, the common security recommendation is to avoid eval() at all costs, as it can be a vector for Cross-Site Scripting attacks (if you want to know more, learn about thescript-src
directive in a Content Security Policy).Awesome @Haroenv, nice to meet you! Thanks for the tip about aliasing, I totally forgot about it. I used webpack to alias out Hogan. I realized we’re actually not using any of the templating built in as we do all our own templates, so I made a quick shim to fill Hogan so it doesn’t error out.
I added this to our webpack config:
And then my fake-hogan.js file is just:
So that gets us to be able to remove
unsafe-eval
🎉While I was figuring this out, I looked briefly at some Mustache alternatives to Hogan.
There are some API differences as well. micromustache is very similar. mustache.js doesn’t have a compile step. Handlebars’ compile returns a function and not an object with render on it.