You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 indirect eval currently do not respect that "normal function" property, when it comes to nonce-based CSPs. Example, with CSP set to script-src 'nonce-foo' 'unsafe-eval':
<script>varmyNormalFunction=eval;varargForMyNormalFunction='import("https://example.com/foo.js")';functionrunIt(x){myNormalFunction(x)}</script><scriptnonce="foo">runIt(argForMyNormalFunction);// this *will not* execute https://example.com/foo.js</script>
<script>varmyNormalFunction=eval;varargForMyNormalFunction='import("https://example.com/foo.js")';</script><scriptnonce="foo">myNormalFunction(argForMyNormalFunction)// this *will* execute https://example.com/foo.js</script>
With the proposed ECMA-262 changes, the behavior of eval and new 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:
what do you think about this behavior?
do you think this change would be web-compatible, with regards to CSP?
The text was updated successfully, but these errors were encountered:
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: