Repository navigation
make-pdf: a NUL character can no longer hide script from the sanitizer - #4762
Merged
Merged
Conversation
…ript handlers make-pdf decoded " and ' after sanitizing, so an image alt, link title or raw HTML attribute could end early and grow an onerror, onload or javascript: href. Quote entities are now read only in text, where they become curly quotes, and the sanitizer also catches handlers and javascript: links that start after a / or a closing quote. Found by GEVA-584. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Handler removal no longer eats a following tag, the stale comment names smartypants, and the changelog entry avoids a sample that the sanitizer strips. Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/red-team#2 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Handler removal always drops the handler's name, even when its unquoted value starts with < (onerror=<!-- code). Review-Finding: p2/red-team#1 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
The typography pass drops U+0000 after sanitizing, so on\u0000error= came back as a live onerror. The sanitizer now drops NUL first. Handler and javascript: removal also keeps page structure: a quoted value holding < or > loses only the handler name, and a javascript: value loses only its scheme. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p1/red-team#1 reader=red-team Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…evive-handlers Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> # Conflicts: # make-pdf/src/render.ts # make-pdf/test/render.test.ts
capy-ai
Bot
changed the base branch from
make-pdf-quote-entities-stay-in-attributes
to
main
November 24, 2026 01:08
|
😎 This pull request was merged. |
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Merged
capy-ai Bot
added a commit
that referenced
this pull request
Nov 24, 2026
- make-pdf no longer lets a NUL character hide an `onerror` handler, a `javascript:` link or a `<script>` tag from its sanitizer. (#4762) - After a blocking fix, /ship's second review round is always a full review whose every reader is recorded with the pass, instead of a narrower re-check whose result could go missing. (#4783, replacing #4781) - /ship's instructions now match how it reviews code. (#4779) - A weekly benchmark record can no longer slip text into the release job's log through its error messages, or lose a model row to an odd model name. (#4782) - Every stable release plan now prints the weekly benchmark's result, so you can see whether this week's gstack measurably fixes more or fewer bugs than the current stable release. (#4755) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make-pdf drops NUL characters before its sanitizer runs, and the sanitizer now repeats until its output stops changing, so neither a NUL nor a removed attribute can turn a Markdown file's raw HTML into a live handler,
javascript:link or<script>tag.Removing a handler or a
javascript:link also keeps the rest of the page. This follows #4761 and is stacked on it until it lands.What changed
sanitizeUntrustedHtmlremoves U+0000 first. The typography pass drops NUL after sanitizing, so the sanitizer used to check a different string from the one the browser got:on\^@error=alert(1),java\^@script:and<scr\^@ipt>all came out live. NUL is the only character that pass drops.<scr onx="a"ipt>came out as a live<script>. A page that never settles after 8 passes prints as escaped text.<or>; otherwise only the handler name goes. Before,<div title="docs/onload='example">Keep me</div><p title='other'>Next</p>lost "Keep me" and the closing tag.javascript:value with no<or>still becomes"#". Any otherjavascript:value loses only its scheme, so no quote is added, and the scheme is also caught after leading spaces or with its colon written as an entity.Security notes
The handler name is always removed, as in #4761, so a value that is kept can't run. Checked by replaying 5,082 generated attack inputs (handler names with NUL, quotes,
<and>inside values, slash and quote separators,javascript:in four attributes, split dangerous tag names) through main, #4761 and this branch, and reading the output with an HTML tokenizer: main leaves 1,908 live, #4761 leaves 1,248, and this branch leaves 0. The tokenizer is htmlparser2, not a real browser.Two display regressions on unusual markup ship as open notes and are fixed in the next make-pdf PR: a quoted handler value holding
>loses only its name, so the value stays next to the tag name; and a reference that starts like an encoded colon, such asΫ, is read as a colon. Neither runs script.Tests
New tests in
make-pdf/test/render.test.tscover NUL inside a handler name, ajavascript:scheme and a tag name, the sanitizer called directly (the diagram pre-pass skips the typography pass), both structure cases, a tag name joined by removing a handler orsrcdoc, andjavascript:after leading spaces or with an encoded colon. Each failed before its fix, except two controls that check a value holding<or>stays neutralized.bun test make-pdf/test/: 326 pass, 0 fail, 13 skip. CI's free-tests run at 1d08b7f passed (https://github.com/garrytan/gstack/actions/runs/45300484014).Why
The NUL bypass was found while reviewing #4761 and was already on main. Both it and the tag-name join let a Markdown file run script in the print browser, which can be the user's own signed-in browser.
Blast radius
Only
make-pdf/src/render.ts's sanitizer. Rendering all 610 tracked Markdown files gives byte-identical output to #4761. Every document now takes at least two sanitizer passes; across 400 files that measured 665 ms before and 893 ms after.Review notes
Below the blocking floor and not fixed here: three security notes recorded privately; no test reaches the escape fallback after 8 passes; the escape fallback prints the page as text without a warning; and the extra pass repeats an older regex that is slow on very long runs of spaces (20,000 spaces take about 2.5 s per pass). Real files stay under 500 ms.
Documentation
Status: current. No documentation changes were needed for the make-pdf sanitizer fix.
Scope: the range e1f0632..1d08b7f (3 commits) changed make-pdf/src/render.ts, make-pdf/test/render.test.ts and changelog.d/make-pdf-nul-cannot-revive-handlers.md. Nothing was staged, unstaged or new. The change is internal to sanitizeUntrustedHtml: it strips NUL characters first, repeats its pass until the output settles (falling back to escaped text if it never does), and tightens how it removes handlers and javascript: links.
Documentation health:
Coverage debt: none. No public command, flag or option changed, and the release note is in the changelog.d fragment.
Diagram drift: none.
Agent notes
Hotfix for the NUL bypass deferred from #4761's review (pre-existing on main). Scope and the structure-preserving rules follow the ruling on #4761. Original bug report credit: GEVA-584. Lane GSTA-832 for GStack Minder.
Approvals
Approved: yes (record r-7a0141649f44). The full approval record stays private.
Plan: exempt: bug fix
Plan check: exempt bug fix
REVIEW_LOOP: passes=2 blocking_found=2 deferred=0 noted=9 fixed=2 scope=frozen ledgers_read=3 dispatches=8
Gate edits: none detected (gate scan tagged 0 hunks at 3f1b57b)
Ruled note: make-pdf/src/render.ts:245:outside-voice at 7af8a07 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-24T00:25:12Z) at 2026-11-24T00:25:13.625Z: display regression on unusual markup; no script runs; 610-file render diff unchanged; fix follows in the Saturday PR (approval a-8ed55faf1de5)
Ruled note: make-pdf/src/render.ts:256:outside-voice at 7af8a07 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-24T00:25:12Z) at 2026-11-24T00:25:13.740Z: display regression on unusual markup; no script runs; 610-file render diff unchanged; fix follows in the Saturday PR (approval a-9db8f241a1c5)