Feedback request on not capturing the caller in new Function
and indirect eval
#679
Labels
addition/proposal
New features or enhancements
needs concrete proposal
Moving the issue forward requires someone to figure out a detailed plan
tc39/ecma262#3374 (which is currently a Stage 2.7 proposal in TC39) is trying to change
new Function
and indirecteval
to not capture context from their caller, thus making them "normal function". The only caller-dependent function remaining in ECMA-262 would be directeval
.By "normal function" I mean a function that follows the normal JavaScript rules and could be implemented in userland: if that changes land,
eval
could easily be implemented with a JS parser and interpreter, both written in JavaScript.Another property of "normal functions" is that these two pieces of code are equivalent:
new Function
and indirecteval
currently do not respect that "normal function" property, when it comes to nonce-based CSPs. Example, with CSP set toscript-src 'nonce-foo' 'unsafe-eval'
:With the proposed ECMA-262 changes, the behavior of
eval
andnew Function
will only depend on the realm/document that they come from, and not on their caller: this means that wrapping them in an intermediate function would have no effect, unlike the example above.More specifically, in both cases https://example.com/foo.js would not be executed, because the nonce is
<script>
-specific and not document-wide.My questions are:
The text was updated successfully, but these errors were encountered: