Repository navigation
Conversation
sanitizeElements() traverses with document.createTreeWalker, which does not descend into a <template>'s content: that content lives in a separate DocumentFragment rather than as child nodes of the element. Both of the sanitizer's protections ride that single traversal, so inside a template neither the forbidden-element list nor the attribute allowlist applied at all. DOMPurify runs after us and does recurse into template content, and its default allowlist excludes script, iframe and noscript. So of the four elements we forbid, it independently removed three and <form> survived end to end. Attributes were not covered at all -- inside a template, name/action/method/autocomplete persisted on elements we meant to strip them from. Recurse into node.content when it is a DocumentFragment, which is how DOMPurify handles the same structure in _sanitizeShadowDOM. walkTree is deliberately untouched: it has 20+ unrelated callers, and nodesToRemove already accumulates across the whole walk, so a recursive pass composes without changing removal semantics. The tests are paired on purpose. A green assertion that <form> is now removed would, on its own, be satisfied by a sanitizer that had stopped running entirely, so the script-inside-template and form-at-top-level controls are what isolate the traversal boundary as the cause. The last test guards the other direction: tables and https links inside a template must still survive.
action_text-trix/app/assets/javascripts/trix.js is a tracked build artifact (only /dist is gitignored), so the source fix in the preceding commit does not reach Action Text consumers until the bundle is regenerated. Rebuilt with `yarn build-js`; the only change is the recursive template traversal.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟢 Approved
The focused implementation and tests correctly cover nested template sanitization without altering unrelated traversal behavior.
0 open findings
What changed in this PR
Recursively sanitizes <template> document fragments, closing element and attribute filtering gaps in inert template content.
Changes:
- Adds recursive template-content sanitization.
- Adds regression and control tests.
- Updates the bundled Action Text build.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
src/trix/models/html_sanitizer.js |
Recurses into template fragments. |
src/test/unit/html_sanitizer_test.js |
Tests template sanitization and permitted content. |
action_text-trix/app/assets/javascripts/trix.js |
Mirrors the sanitizer fix in the bundle. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
HTMLSanitizer.sanitizeElements()walks the document withdocument.createTreeWalker, which does not descend into a<template>'s content — that content lives in a separateDocumentFragmentrather than as child nodes of the element. Both of the sanitizer's protections ride that single traversal, so inside a<template>neither the forbidden-element list nor the attribute allowlist was applied.DOMPurify runs after us and does recurse into template content, and its default allowlist already drops
script,iframeandnoscript. Butformis in its default allowlist, so a<form>inside a<template>survived end to end, and disallowed attributes (name,action,method,autocomplete, …) persisted on elements we meant to strip them from.Recurse
sanitizeElements()intonode.contentwhen it is aDocumentFragment, mirroring how DOMPurify handles the same structure in_sanitizeShadowDOM.walkTreeis untouched — it has many unrelated callers — and the recursive pass accumulates into the samenodesToRemovelist, so removal semantics are unchanged. This composes with the<style>forbid from #1369: a<style>inside a template is now stripped too.The tests are paired to isolate the traversal boundary as the cause rather than a blanket filter failure: a
<script>inside the same<template>(independently removed by DOMPurify) and a<form>at top level (already removed) are controls alongside the new<form>-in-template assertion. A final test confirms permitted content — tables andhttpslinks — inside a template still survives.Targeting 2.1.20, alongside #1369 and #1357.