-
Notifications
You must be signed in to change notification settings - Fork 74
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
should null
& undefined
for sinks requiring TT be a passthrough ?
#379
Comments
Should the policy be given the raw value instead of coercing to a string? At least taking nullable strings would help with this issue? |
Coercing to a string was intentional, though the main case was to prevent passing objects to policy functions, as they then could enable several bypasses (e.g. objects that stringify to different values each time to bypass pre-sanitization checks). Stringifying removes that attack surface from the API. Though, admittedly, this is less of a concern for other primitive types like null/undefined. Returning null or undefined (vs |
|
Why? Be aware that for values
|
#414 has some context, but indeed:
|
Behavior confirmed by https://jsfiddle.net/ejvc1up2/1/. |
Consider the following scenario:
In a TT environment this would require
null
to be TrustedScript value. Say we define a default policy to handle such cases and automatically sign those values. We will notice that upon enteringcreateScript
hooknull
&undefined
is automatically coerced to a string. Simply returning the value will causesetTimeout
andsetInterval
to execute without throwing an error when, in fact, the API should throw an error notifying you about the invalid argument type and how you can remedy the situation.Maybe I am not that familiar with all the ways in which TrustedTypes can be used to handle such scenarios but based on the knowledge I have right now it seems to me that one solution would be to allow
null
&undefined
to be a passthrough such that native APIs can throw the relevant error instead of being masked behind a TT validation error, or not thrown at all. The APIs also have different behavior for those values.Consider this:
setTimeout
,setInterval
,eval
,textContent
,innerHTML
- when on a Script tag - all hitpolicy.createScript
and they all have different behaviors. They either accept null (eval), throw an error (setTimeout), or coerce to string. Thus, handling this at the policy level to accept something is not a good option since it can start masking legitimate errors in the code.The text was updated successfully, but these errors were encountered: