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
Verify script enforcement applies even if the source text is modified before require-trusted-types-for 'script' is set.
Current spec [1] essentially caches the "script text" associated to a
script element: it is initially empty and updated by various APIs calls.
The "prepare the script element" algorithm is modified [2], so that
"child text content" would go through the default policy if it does
not match the cached "script text" [3].
Script enforcement could be alternatively be implemented by flags [4].
In that case, it might be tempting not to update the flags when the API
calls modifying a script are performed before Trusted Types are
actually enforced, with the rationale that these API calls are not
considered untrusted at that time. For a cache-based implementations,
this would be equivalent to not caching the "script text" until the
first time it is set in a context when Trusted Types is enforced.
However, WebKit and Chromium follow the spec and really try and run
the default policy on the script text, even if the script text was
modified before TrustedTypes enforcement got enabled. This PR adds
tests to verify this behavior for HTML and SVG scripts.
For completeness, this also verifies that if we remove the
require-trusted-types-for meta tag before the test is executed, then
TrustedTypes enforcement remains enabled per [5].
[1] https://w3c.github.io/trusted-types/dist/spec/#enforcement-in-scripts
[2] https://w3c.github.io/trusted-types/dist/spec/#slot-value-verification
[3] https://w3c.github.io/trusted-types/dist/spec/#prepare-the-script-text
[4] w3c/trusted-types#579
[5] https://www.w3.org/TR/CSP3/#meta-element
0 commit comments