Repository navigation
Enable createParserOptions, passing a sanitizer to trusted types - #606
Conversation
|
LGTM |
ced3862 to
d44dcea
Compare
|
I've made some changes:
(Note: this PR will fail build until we merge the latter) |
|
Are you able to fix the build failure now? |
I'll revisit this once I have the HTML counterpart ready. |
|
Also, reportedly this impacts |
Added prose and examples for this |
|
(The build failure is in main, trying to resolve separately. Do you have an idea maybe @lukewarlow ?) |
|
In Also I feel like we should probably always return a Sanitizer object, instead of one of three options? Otherwise it seems easy to accidentally write code (not sure what for though?) that only works with a subset. |
It's a good point. I guess we need to return a clone of the underlying sanitizer if the getter is invoked so that you couldn't get a
Yea I was contemplating that. SGTM |
`createParserOptions` receives a `SetHTML{Unsafe}Options` and turns them into
a `TrustedParserOptions` using the given method from the policy config.
This is the `trusted-types` part of #594
(Need to wire it to HTML as well)
Co-authored-by: Anne van Kesteren <[email protected]>
Co-authored-by: Anne van Kesteren <[email protected]>
Co-authored-by: Anne van Kesteren <[email protected]>
* Reject `TrustedHTML` with an unvetted sanitizer or `runScripts` Without a `TrustedHTMLParserOptions` or a default policy's `createParserOptions`, a caller-supplied `sanitizer` or `runScripts: true` could make vetted markup unsafe. Fixes #615. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Check unvetted options in parser options and ignore empty `sanitizer` An empty `sanitizer` is the IDL default, so it counts as no sanitizer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Don't reject `runScripts` without a parser policy `createContextualFragment` sets `runScripts` to true, so rejecting it would break `TrustedHTML` there. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * Reject author-supplied `runScripts` without a parser policy Sinks that construct their own options, like `createContextualFragment`, pass false for the new `optionsFromAuthor` argument. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
AI reviewLine numbers are
|
All addressed. |
This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1712499}
This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1712499}
This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1712499}
AI feedbackReviewed at c5aa609, together with whatwg/html#12583. Suggestions
Nits
|
Added a note in the OP
Added a note in the OP. Will make sure that it's covered in the WPT PR.
Done
Done |
SHA: fbe9462 Reason: push, by noamr Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fragment parsing sinks now call "get trusted type compliant input" instead of "get trusted type compliant string". This lets a default policy's `createParserOptions` supply a sanitizer or change script-running behavior for `innerHTML`, `outerHTML`, `insertAdjacentHTML()`, `createContextualFragment()`, `setHTMLUnsafe()`, and `parseHTMLUnsafe()`. This only applies in HTML documents. `srcdoc`, `document.write()`, `DOMParser`'s `parseFromString()`, and `execCommand("insertHTML")` are unchanged for now.
The fragment parsing algorithm steps now take a single mode (safe, unsafe, or legacy) instead of a safe boolean and a scripting mode. They also handle sanitization for all of these sinks.
This also removes the `{}` default from the `sanitizer` member of `SetHTMLUnsafeOptions` and `ParseHTMLUnsafeOptions`. `setHTML()` and `parseHTML()` no longer mutate a passed `Sanitizer`, and configuring a sanitizer no longer mutates the built-in safe default configuration. `createContextualFragment()` now creates its fallback `body` in the node document of the range's start node.
Goes with w3c/trusted-types#606.
Co-authored-by: Simon Pieters <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…erOptions, a=testonly Automatic update from web-platform-tests Apply latest spec changes for createParserOptions This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1712499} -- wpt-commits: b5daf96de870b547d88d1a157a0be7b631db1f04 wpt-pr: 63321
…erOptions, a=testonly Automatic update from web-platform-tests Apply latest spec changes for createParserOptions This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <vogelheimchromium.org> Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com> Cr-Commit-Position: refs/heads/main{#1712499} -- wpt-commits: b5daf96de870b547d88d1a157a0be7b631db1f04 wpt-pr: 63321 UltraBlame original commit: a158e7688437ddc49df990c7863dd38fbf1ffd0d
…erOptions, a=testonly Automatic update from web-platform-tests Apply latest spec changes for createParserOptions This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <vogelheimchromium.org> Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com> Cr-Commit-Position: refs/heads/main{#1712499} -- wpt-commits: b5daf96de870b547d88d1a157a0be7b631db1f04 wpt-pr: 63321 UltraBlame original commit: a158e7688437ddc49df990c7863dd38fbf1ffd0d
…erOptions, a=testonly Automatic update from web-platform-tests Apply latest spec changes for createParserOptions This aligns with: - whatwg/html#12583 - w3c/trusted-types#606 Key changes: - Remove default `= {}` from `SetHTMLUnsafeOptions.sanitizer` and `ParseHTMLUnsafeOptions.sanitizer` in IDL, and only populate `sanitizer` on the dictionary passed to `createParserOptions` when provided. - Update `TrustedTypePolicy.createParserOptions` and `CreateParserOptionsCallback` to accept optional `SetHTMLUnsafeOptions` and variadic `any... args`, passing `"TrustedHTMLParserOptions"` and the sink name when invoked on the default policy. - Require default policy `createParserOptions` vetting when author supplied parser options specify `runScripts: true` or a non-empty sanitizer, even when the input is already a `TrustedHTML`. (This is a breaking change! but still protected by the flag) - Allow any `TrustedHTMLParserOptions` (even without a sanitizer) to satisfy Trusted Types enforcement for HTML fragment sinks, and use `TrustedTypesCheckForFragment` in `Document.parseHTMLUnsafe`. - Bypass `createParserOptions` and ignore sanitization in XML documents, always requiring `TrustedHTML` for XML fragment sinks. Bug: 491743369 Change-Id: Ia0b35e3f8720dc318aacafc117098fb3db508b30 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8496967 Reviewed-by: Daniel Vogelheim <vogelheimchromium.org> Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com> Cr-Commit-Position: refs/heads/main{#1712499} -- wpt-commits: b5daf96de870b547d88d1a157a0be7b631db1f04 wpt-pr: 63321 UltraBlame original commit: a158e7688437ddc49df990c7863dd38fbf1ffd0d
…izer in each call, a=testonly Automatic update from web-platform-tests TrustedParserOptions: return a new sanitizer in each call This is instead of retaining a frozen copy. See w3c/trusted-types#606 Bug: 491743369 Change-Id: Ida4d1a661edb8475cbc4a1b2ce0d0e3d38913024 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8097523 Reviewed-by: Daniel Vogelheim <[email protected]> Commit-Queue: Noam Rosenthal <[email protected]> Cr-Commit-Position: refs/heads/main@{#1663095} -- wpt-commits: c1e067e2346c22c0fc98bafed6618c3d92b06af0 wpt-pr: 61339
createParserOptionsreceives an optionalSetHTMLUnsafeOptionsdictionary (orParseHTMLUnsafeOptions) and turns it into aTrustedHTMLParserOptionsobject using thecreateParserOptionsmethod defined on the policy.createParserOptionsserves as the primary Trusted Types mechanism for HTML fragment parsing sinks (setHTMLUnsafe,innerHTML,outerHTML,insertAdjacentHTML, andcreateContextualFragment), allowing a policy to configure aSanitizer, and allow/disallow script execution:Passing a
TrustedHTMLParserOptionsobject directly into a fragment parsing sink satisfies Trusted Types enforcement for HTML documents, allowing raw markup strings to be parsed without requiring aTrustedHTMLobject or invokingcreateHTML.When a default policy defines
createParserOptions, calls to fragment parsing sinks automatically produce aTrustedHTMLParserOptionsthat satisfies the sink, applying the policy's sanitizer and script-execution settings. Note that the default policy takes precedence even if less restrictive than the caller - it can vet a less restrictive sanitizer, or enable script execution.If no
TrustedHTMLParserOptionsis provided (either by the caller or via a default policy'screateParserOptions), we fall back to the existingget trusted type compliant string, requiringinputto be aTrustedHTMLor passing it to the default policy'screateHTML. This ensures backwards compatibility for policies that only definecreateHTML, and covers string-only sinks that do not support parser options (e.g.document.write(), XML documents, andiframe.srcdoc). Note thatTrustedHTMLdoes not receive special handling whencreateParserOptionsis present in the policy - in supported browsers/sinks,createHTMLandTrustedHTMLare a fallback only.For sinks where the full HTML is not available up front (such as streaming parsing),
get trusted type compliant parser optionsis invoked withthrowIfMissing = true, requiring the caller to supply aTrustedHTMLParserOptionsor requiring the default policy to definecreateParserOptions.When
TrustedHTMLis provided together with author-specifiedrunScriptsor sanitizer, an exception is throws - as this can lead to an insecure blend, see EvaluatecreateHTMLinteraction with sanitizerreplaceWithChildren(andrunScripts?) #615. This includes explicitly passing"default"tosetHTMLUnsafe(this can be relaxed later on).TrustedHTMLParserOptions` does not expose any interface methods or attributes to JavaScript; it acts as an immutable, opaque token whose internal associated configuration and script-execution settings are inspected directly by specification algorithms.
report-onlymode might report twice if bothcreateParserOptionsandcreateHTMLviolate the policy.Security model: As documented in the Security Considerations, a
createParserOptionscallback that does not configure a sanitizer to remove unsafe markup (e.g. scripts or event handlers) grants a pass-through to parse arbitrary markup without DOM XSS protection. It is the responsibility of the policy author / security auditor to ensurecreateParserOptionsenforces adequate sanitization, or that aTrustedHTMLParserOptionsobject is only passed to trusted source (similar to the policy objects themselves).As a followup, we should evaluate the (existing) combination of
TrustedHTMLwith sanitizer. Opened #615 for that.This is the
trusted-typespart of #594 together with whatwg/html#12583.Note that this should only be merged when wired into the HTML standard, once the sanitizer is itself upstreamed.
Preview | Diff