Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upInclude the string to be compiled in the call to `HostEnsureCanCompileStrings` #938
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
domenic
Jun 21, 2017
Member
Sounds good in theory. The only reason we didn't do this at the time was because it wasn't needed, IIRC.
There are a couple of tricky things:
- How do you want to handle non-strings? Currently in a CSP-restricted environment,
eval(nonString)will throw. (I wonder if we have tests for that?) One refactoring would be to ensure things are a string before passing them to HostEnsureCanCompileStrings. If we do that, then behavior will change, and we'll bail out before ever hitting HostEnsureCanCompileStrings. - Similarly, for
Function()and its various friends (GeneratorFunction(),AsyncFunction()), do we handle arg coercion before or after HostEnsureCanCompileStrings? This would change which error is thrown when doing e.g.Function({ toString() { throw 5; }). - For
Function()and friends, what text should be passed? Should it be the body text of the function, which is directly passed as an argument? Or perhaps we should re-serialize the entire function, after we've assembled the various arguments toFunction()into an actual function? The former would probably work for your purposes, although it's a bit weird to be doing checks on something that isn't standalone evaluatable source code. Maybe it would help if we named the new parameter something likesourceTextHintorproximateSourceTextinstead of justsourceText, with a reasonable explanation.
|
Sounds good in theory. The only reason we didn't do this at the time was because it wasn't needed, IIRC. There are a couple of tricky things:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mikewest commentedJun 21, 2017
To improve the quality of CSP reports, it would be helpful for
HostEnsureCanCompileStrings()to include the string to be compiled as an argument.HostEnsureCanCompileStrings(callerRealm, calleeRealm, source)seems ideal. :)The goal is to ensure that we can include a sample of the script which violates the policy when generating a CSP violation report. We're doing this for inline
<script>...</script>blocks today, and layeringeval()and the like on as well would be helpful.