Skip to content

make-pdf: a NUL character can no longer hide script from the sanitizer - #4762

Merged
capy-ai[bot] merged 8 commits into
mainfrom
make-pdf-nul-cannot-revive-handlers
Nov 24, 2026
Merged

capy-ai[bot] merged 8 commits into
mainfrom
make-pdf-nul-cannot-revive-handlers

Conversation

@garrytan

@garrytan garrytan commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

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
  • sanitizeUntrustedHtml removes 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.
  • The sanitizer repeats its pass until the output stops changing. Removing a handler could join the two halves of a tag name, so <scr onx="a"ipt> came out as a live <script>. A page that never settles after 8 passes prints as escaped text.
  • A quoted handler value is removed with its name only when it holds no < 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.
  • A quoted javascript: value with no < or > still becomes "#". Any other javascript: 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 &#x3ab;, is read as a colon. Neither runs script.

Tests

New tests in make-pdf/test/render.test.ts cover NUL inside a handler name, a javascript: 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 or srcdoc, and javascript: 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:

  • make-pdf/SKILL.md.tmpl: current. It does not describe sanitizer internals.
  • README.md: current.
  • SECURITY.md: current.
  • ARCHITECTURE.md: current. Its sanitization section covers browse egress, not make-pdf.

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)

{
  "schema_version": 1,
  "pr": 4762,
  "head": "1697be62ad67b7fbfdb8a700db288f5bb6bf8d3c",
  "version": "1.103.0.0",
  "base": "main",
  "gate": {
    "make-pdf": {
      "pass": 326,
      "fail": 0,
      "skip": 13
    }
  },
  "calls": 40,
  "session_kind": "unattended",
  "run": "gsta832-nul-ship",
  "head_tree": "1ba904499288a8650efd1c12e672c70b43e71c83",
  "product_patch_id": "8cd1a8b5f02a3834a77b8e44ec3da2516af763f5",
  "gstack_version": "1.103.0.0",
  "review_depth": {
    "depth": "full",
    "class": "code",
    "runtime_lines": 27,
    "rules": "33831f8248a814fd",
    "base": "40986b7c76ff51bd85267547fabd996cdb77cb88",
    "registry": "40986b7c76ff51bd85267547fabd996cdb77cb88",
    "gate_scan": {
      "tagged": 0,
      "head": "1697be62ad67b7fbfdb8a700db288f5bb6bf8d3c"
    },
    "reasons": [
      "runtime=27"
    ],
    "risk": [],
    "mode": "panel"
  },
  "pregate": "pass @1ba904499288 (8 checks, current for 1697be62ad67)",
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": [],
    "related": []
  },
  "docs": {
    "status": "current",
    "scope": "make-pdf/SKILL.md.tmpl, README.md, SECURITY.md, ARCHITECTURE.md, docs/"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 2,
    "deferred": 0,
    "noted": 9,
    "fixed": 2,
    "scope": "frozen",
    "rounds": 2,
    "ledgers_read": 3,
    "dispatches": {
      "specialist": 6,
      "red-team": 2
    }
  },
  "ruled_notes": [
    {
      "finding": "make-pdf/src/render.ts:245:outside-voice",
      "head": "7af8a074e481468a43587f155dd0ccfe9529cb7a",
      "by": "GStack Minder (GSTA-36)",
      "reason": "display regression on unusual markup; no script runs; 610-file render diff unchanged; fix follows in the Saturday PR",
      "at": "2026-11-24T00:25:13.625Z",
      "approval": "a-8ed55faf1de5",
      "relayed": "GSTA-36:2026-11-24T00:25:12Z"
    },
    {
      "finding": "make-pdf/src/render.ts:256:outside-voice",
      "head": "7af8a074e481468a43587f155dd0ccfe9529cb7a",
      "by": "GStack Minder (GSTA-36)",
      "reason": "display regression on unusual markup; no script runs; 610-file render diff unchanged; fix follows in the Saturday PR",
      "at": "2026-11-24T00:25:13.740Z",
      "approval": "a-9db8f241a1c5",
      "relayed": "GSTA-36:2026-11-24T00:25:12Z"
    }
  ],
  "gate_dispositions": [],
  "carry": {
    "from": "1d08b7fe50e753f9e6d4ab492005a8d300ba4769",
    "reason": "stack parent make-pdf-quote-entities-stay-in-attributes landed + base merge + test-only change + release metadata",
    "product_patch_id": "8cd1a8b5f02a3834a77b8e44ec3da2516af763f5",
    "changed_paths": [
      "product:.github/workflows/free-tests.yml",
      "metadata:changelog.d/free-tests-runner-8-core.md",
      "metadata:changelog.d/land-reuses-merged-tree-ci-run.md",
      "metadata:changelog.d/run-ids-not-card-numbers.md",
      "product:crew/docs/captain.md",
      "product:docs/TESTING_INTERNALS.md",
      "product:docs/ship-policy.md",
      "product:docs/troubleshooting.md",
      "product:lib/gstack-post.ts",
      "product:lib/land-merged-checks.ts",
      "product:lib/land-merged-ci.ts",
      "product:lib/run-evidence.ts",
      "test:test/gstack-post.test.ts",
      "test:test/land-merged-ci.test.ts"
    ],
    "merge_commits": 1,
    "range_diff": "1:  b61cd9a3 = 1:  b61cd9a3 make-pdf keeps quote entities inside attributes so they cannot add script handlers\n2:  38ff446c = 2:  38ff446c fix: pre-landing review fixes\n3:  e1f06324 = 3:  e1f06324 fix: pre-landing review fixes\n4:  3f1b57bd = 4:  3f1b57bd make-pdf: a NUL character can no longer hide script from the sanitizer\n5:  7af8a074 = 5:  7af8a074 fix: pre-landing review fixes\n6:  1d08b7fe = 6:  1d08b7fe make-pdf: changelog entry wording\n-:  -------- > 7:  1697be62 Rerun checks after retargeting to main",
    "covers": [
      "pre-landing review",
      "adversarial review",
      "gate integrity",
      "documentation audit"
    ],
    "reruns": [
      "CI at head (gstack-ship-queue ready requires it); test and helper code changed since the reviewed head runs there unreviewed"
    ],
    "ancestry": "linear",
    "trees": [
      "5cf70f1902cc5113b59bdaf153a8037814d02aa3"
    ]
  }
}
{"head":"7af8a074e481468a43587f155dd0ccfe9529cb7a","run":"gsta832-nul-ship","mark":"stop","tree":"6bd058945870971ea948ae41a9767305d9f52d40","at":"2026-11-24T00:24:21.326Z"}
{"head":"1d08b7fe50e753f9e6d4ab492005a8d300ba4769","version":"1.103.0.0","gstack_version":"1.103.0.0","run":"gsta832-nul-ship","review_loop":{"passes":2,"blocking_found":2,"deferred":0,"noted":9,"fixed":2,"scope":"frozen","rounds":2,"ledgers_read":3,"dispatches":{"specialist":6,"red-team":2}},"depth":"full"}

Open in Capy

garrytan and others added 7 commits November 23, 2026 23:13
…ript handlers

make-pdf decoded &quot; and &#39; 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=<!--&#10;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
capy-ai Bot changed the base branch from make-pdf-quote-entities-stay-in-attributes to main November 24, 2026 01:08
@trunk-io

trunk-io Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit f740221 into main Nov 24, 2026
54 checks passed
@garrytan garrytan mentioned this pull request Nov 24, 2026
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>
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.

1 participant