Open Bug 2051256 Opened 3 months ago Updated 14 days ago

setHTMLUnsafe: Observable difference between sanitizer and the optimized no sanitizer path

Categories

(Core :: DOM: Security, defect)

defect

Tracking

()

ASSIGNED

People

(Reporter: tschuster, Assigned: keithamus)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

nsContentUtils::SetHTMLUnsafe has an optimization that bypasses the Sanitizer and inert document creation path: https://searchfox.org/firefox-main/rev/0c4c351481d11be32f41af409dbc59122bef80a2/dom/base/nsContentUtils.cpp#6608-6635

This optimization is observable with the following test case:

document.body.setHTMLUnsafe("<div><template shadowrootmode='open'></template></div>",  { sanitizer: {} } )
document.body.setHTMLUnsafe("<div><template shadowrootmode='open'></template></div>" )

The first invocation creates the tree: div> > <template>
The second one creates <div> with a #shadow-root.

I actually think the second one makes more sense. Otherwise it seems impossible to ever create a shadow root at all? I need to investigate where this difference comes from, but my hunch is the inert document we use for parsing in the Sanitizer case.

The severity field is not set for this bug.
:freddy, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(fbraun)
Severity: -- → S4
Flags: needinfo?(fbraun)

I think with the sanitize while parsing change we would not have different parser code paths anymore and this difference should go away automatically. This is probably missing a test that we should write.

Depends on: 2062652

setHTMLUnsafe() had a separate fast path when no sanitizer was passed, and
it parsed differently from default path; the latter disallowed declarative
shadow roots, ignored the document's quirks mode.

This change deletes the fast path; SetAndFilterHTML now takes nullable sanitizer
options where null is the spec's permissive default. This "fast path" should
no longer matter now we're sanitizing while parsing.

Assignee: nobody → mozilla
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: