Skip to content

Reject TrustedHTML with an unvetted sanitizer or runScripts - #616

Merged
noamr merged 4 commits into
w3c:create-parser-optionsfrom
zcorpan:trustedhtml-untrusted-options
Sep 28, 2026
Merged

noamr merged 4 commits into
w3c:create-parser-optionsfrom
zcorpan:trustedhtml-untrusted-options

Conversation

@zcorpan

@zcorpan zcorpan commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Without a TrustedHTMLParserOptions or a default policy's createParserOptions, an author-supplied non-empty sanitizer or runScripts: true could make vetted markup unsafe.

Fixes #615. Based on #606.


Preview | Diff

zcorpan and others added 2 commits September 25, 2026 12:43
Without a `TrustedHTMLParserOptions` or a default policy's `createParserOptions`, a caller-supplied `sanitizer` or `runScripts: true` could make vetted markup unsafe.

Fixes w3c#615.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An empty `sanitizer` is the IDL default, so it counts as no sanitizer.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@zcorpan

zcorpan commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm not sure about the XML case. Is there a reason to not throw in general in the XML case if you provide a non-empty sanitizer or runScripts: true?

`createContextualFragment` sets `runScripts` to true, so rejecting it would break `TrustedHTML` there.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@zcorpan zcorpan changed the title Reject TrustedHTML with an unvetted sanitizer or runScripts Reject TrustedHTML with an unvetted sanitizer Sep 25, 2026
@zcorpan

zcorpan commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

In XML-parsing entry points I believe the sanitizer is always empty, so it won't throw.

Changed to not throw for runScripts: true since createContextualFragment sets it.

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]>
zcorpan added a commit to whatwg/html that referenced this pull request Sep 26, 2026
This lets Trusted Types reject author-supplied `runScripts` without breaking `createContextualFragment`. See w3c/trusted-types#616.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@zcorpan zcorpan changed the title Reject TrustedHTML with an unvetted sanitizer Reject TrustedHTML with an unvetted sanitizer or runScripts Sep 26, 2026
@noamr
noamr merged commit f9556e5 into w3c:create-parser-options Sep 28, 2026
3 checks passed
noamr pushed a commit to whatwg/html that referenced this pull request Sep 28, 2026
This lets Trusted Types reject author-supplied `runScripts` without breaking `createContextualFragment`. See w3c/trusted-types#616.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
zcorpan added a commit to web-platform-tests/wpt that referenced this pull request Sep 29, 2026
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Oct 6, 2026
…hat need vetting, a=testonly

Automatic update from web-platform-tests
Test `TrustedHTML` with parser options that need vetting

For w3c/trusted-types#616.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
--

wpt-commits: 43681d686ca43bfb9ae5e0bb9e775dc25246d9c4
wpt-pr: 63042
noamr pushed a commit to whatwg/html that referenced this pull request Oct 6, 2026
This lets Trusted Types reject author-supplied `runScripts` without breaking `createContextualFragment`. See w3c/trusted-types#616.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
noamr added a commit that referenced this pull request Oct 7, 2026
* Enable createParserOptions, passing a sanitizer to trusted types

`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)

* Update TrustedParserOptions to expose only Window

* Update index.bs

* Introduce `runScripts` and potentially "throw if missing"

* mutation

* Wrap createHTML+createParserOptions

* Add prose and examples for createParserOptions

* Fix build

* Update spec/index.bs

Co-authored-by: Anne van Kesteren <[email protected]>

* Update spec/index.bs

Co-authored-by: Anne van Kesteren <[email protected]>

* Update spec/index.bs

Co-authored-by: Anne van Kesteren <[email protected]>

* nits

* Ensure mutations in place don't work

* biblio

* Use sanitizer() method

* Use a sanitizer() method

* Fix up sinkGroup argument

* Fix indentation

* Add note about

* Only expose createParserOptions in Window

* Allow null sanitizer

* Throw here when returning a sanitizer for an XML doc

* Undo throwing based on doc type

* get trusted compliant input does not need a type

* Fix throwIfMissing polarity for stream inputs and default sanitizer config to null

* No need for 'stream'

* Update spec/index.bs

Co-authored-by: Simon Pieters <[email protected]>

* Update spec/index.bs

Co-authored-by: Simon Pieters <[email protected]>

* nits

* Fix a few arguments

* Fix issues from offline review

* TrustedHTML

* Inverse calls. When createParserOptions returns a sanitizer,
we don't need to also call createHTML.

* No need to call createHTML if sanitizer is invoked

* nits

* Handle preset

* Refine TrustedHTML case

* Fix build

* typo

* Fix cloning

* rename algo

* notes

* Remove TrustedParserOptions rfrom typedef

* Address review comments on createParserOptions and sanitizer config

* Pass documentType ('html' or 'xml') instead of boolean

* Editorial: address review comments on TT and XML handling

* Editorial: clean up XML note and assert non-null configuration

* Update spec/index.bs

Co-authored-by: Anne van Kesteren <[email protected]>

* nits

* config->uration

* TrustedHTMLParserOptions without members

* Use compliantOptions' sanitizer

* Remove TrustedHTML special casing

* Clarify that createHTML is a fallback

* Add a table for different inputs/outputs

* Improve table

* Add sanitizer column

* Allow policy to set runScripts to true

* Wrap table in div

* Move table to non-normative section

* Make note more concise

* Reject `TrustedHTML` with an unvetted sanitizer or `runScripts` (#616)

* 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]>

* Address AI review comments

* The default safe config needs vetting

* Helper for arguments

---------

Co-authored-by: Anne van Kesteren <[email protected]>
Co-authored-by: Simon Pieters <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
zerox80 pushed a commit to zerox80/firefox that referenced this pull request Oct 16, 2026
…hat need vetting, a=testonly

Automatic update from web-platform-tests
Test `TrustedHTML` with parser options that need vetting

For w3c/trusted-types#616.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
--

wpt-commits: 43681d686ca43bfb9ae5e0bb9e775dc25246d9c4
wpt-pr: 63042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants