Repository navigation
make-pdf: quotes in alt text, titles and raw HTML can no longer add script handlers (GST-3641) - #4761
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>
|
😎 This pull request was merged. |
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>
Merged
capy-ai Bot
added a commit
that referenced
this pull request
Nov 24, 2026
- `/ship` now tells you what to change when GitHub refuses a push for email privacy. (#4748) - The release gate's /cso check accepts the low-confidence hypotheses /cso now reports. (#4753) - /cso reports every security finding the code supports instead of dropping most of them. (#4739) - /cso can search the whole repository in one call, and a daily report now lists its low-confidence hypotheses. (#4742) - A first version's plan and try-it message now open with the owner's own words, and the build is tried the same way he will try it before he is asked. (#4759) - A first version's public export now keeps out the owner's short quotes and his reasons to leave something out, and a phone first-use check installs a build the cloud phone can actually run. (#4772) - Three intermittent test failures are fixed. (#4745) - Free Tests runs its shards on 8-core runners again. (#4749) - A land that waits on an earlier CI run now decides on what that run actually did. (#4763) - Landing a PR no longer starts a new CI run when one for the same merged code is already running or has passed. (#4760) - /ship no longer misses a file-mode change from main on files whose names start with `:`. (#4774) - make-pdf keeps quotes in alt text, link titles and raw HTML attributes inside the attribute, so a Markdown file can no longer add an `onerror`, `onload` or `javascript:` link that runs in the print browser. (#4761) - Posting a PR body that lists earlier /ship runs no longer stops for a phone number that isn't there. (#4747) - A first version's public export now catches a short owner quote whose padding or quote marks are encoded. (#4778) - A first version's public export now also keeps out a short owner quote written with spaces just inside its quote marks. (#4776) - Posting a PR body that lists earlier /ship runs no longer stops for a card number that isn't there. (#4751) - /ship no longer asks for an extra reader when you merge the base branch next to code that was already reviewed. (#4754) - /ship no longer plans narrow re-checks after a fix. (#4741) - /ship can't quietly gain new refusals. (#4740) - `gstack-upgrade` no longer refuses to run after you disable skills. (#4743) - The free test suite splits its shards from this week's recorded test times. (#4744) - gstack now writes up a failed or shelved attempt before closing it. (#4735) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
capy-ai Bot
added a commit
that referenced
this pull request
Nov 24, 2026
#4762) 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 `` 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. 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#2 reader=red-team Review-Finding: p2/red-team#1 reader=red-team Review-Finding: p1/red-team#1 reader=red-team
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.
Quotes in image alt text, link titles and raw HTML attributes now stay inside their attribute, so a Markdown file can no longer add an
onerror,onloadorjavascript:link that runs in make-pdf's print browser.Why: the print browser runs page scripts, and on main a crafted image caption made it send the document's own text to another address.
Nothing to do: ordinary Markdown prints the same (609 of gstack's own Markdown files render identically).
What changed
render()used to turn",','and'back into straight quotes across the whole page after the sanitizer had run, so an image caption such asx"/onerror="alert(1)printed as a live handler. That pass is gone. Smartypants now reads those entities as quotes inside its text runs only, and every quote in a text run comes out curly, so an entity can never become attribute or tag syntax. Tags, code and URLs keep their entities, which the browser shows as the same characters.javascript:links after/or a closing quote. The browser starts an attribute after whitespace, a/or a closing quote. The sanitizer only looked after whitespace, so inside a raw HTML block<img src="x"/onerror="…">,<img src="x"onerror="…">,<svg/onload=…>and<a title="t"href="javascript:…">passed straight through on main. The handler andjavascript:rules now match after all four, and the handler's name is always removed, whatever its value starts with.<, so removing handler text from inside a title, or from a code span such asa/onset=2, no longer eats the closing quote or the</code>tag.Security notes
Does the print browser run page scripts? Yes, on both engines. Both open the staged HTML over a loopback server at
http://127.0.0.1:<port>/<nonce>/document.htmlwith JavaScript on: the Aside path injects its error hook withPage.addScriptToEvaluateOnNewDocumentand both paths poll page expressions, so script is required there, and nothing sets a Content Security Policy or intercepts requests. Checked on this branch's base (a256d15) with gstack's own browser (headless Chromium 158): a raw-HTML<svg/onload=fetch(…)>and an image caption whose encoded quotes addonloadeach sent a request to a local listener duringmake-pdf generate, the first with the page URL (including the per-render nonce) and the document's first 30 characters. On this branch the same two files sent nothing. Aside was not run (macOS only); it runs the same page in a tab of the user's Aside browser.What a script could reach there:
document.html; images are inlined as data URIs).--allow-networksays: make-pdf's offline posture is enforced by the sanitizer and the image inliner, not the browser. A script can send the document anywhere, and can send requests to other loopback services on the machine.http://127.0.0.1, so Chromium refusesfile://reads, and the loopback server serves only the staging directory, checked on the resolved path.Still open, older than this PR:
javascript:scheme with a NUL inside it (on<NUL>error=) passes the sanitizer and comes out live. This exists on main today (since browse --session before the command, Gemini AQ. keys, /verify trust across worktrees, and two more fixes from outside reports #4684) and this PR neither causes nor worsens it. The fix (strip those characters before sanitizing, and make the handler andjavascript:rules edit only the attribute name, never quotes) is the next PR, opened now from main.javascript:link written with numeric entities (javascript:) is not rewritten; it only runs if someone clicks it.style,srcset, SVGhrefand mediasrcstill look only after whitespace, so raw HTML glued with/or a quote can fetch a remote URL at print time (no script).Tests
bun test make-pdf/test/: 317 tests ran, 0 failed (final check at e1f0632).typecheckclean;typecheck:test812 known, none new.Why
make-pdf prints Markdown that often comes from somewhere else: a README, a report an agent fetched, a document a user was sent. The sanitizer is what stands between that text and a browser that runs scripts, and both bypasses let script run with access to the document being printed and to the network.
Blast radius
make-pdf/src/render.ts(sanitizer and render pipeline) andmake-pdf/src/smartypants.ts. Rendered all 609 tracked Markdown files with main and with this branch, reading quote entities as characters: 0 differ. Handler-looking text such as/onload=xis now removed wherever it appears, URLs and code included; the same was already true after whitespace.Test Coverage
New tests in
make-pdf/test/render.test.tscheck what the browser's tokenizer would see, not exact strings: anonerrorfrom an image alt, anonloadfrom an image title (which must not swallow the next paragraph), a secondhreffrom a link title, ajavascript:href from a raw-HTML title, single-quote entities ending a raw attribute, handlers orjavascript:links after/or a closing quote, handler values starting with<or a quote (including an HTML comment opener followed by an encoded newline), handler text in a code span that must not eat</code>, and a positive control. Two smartypants tests pin the contract. On base, with only the tests applied, 7 of the first 10 fail; the image-title test passes on base and guards a regression this change would otherwise cause.Pre-Landing Review
Pre-Landing Review: 10 issues — 3 auto-fixed, 0 asked, 1 deferred, 4 noted, 2 open as ruled notes.
Deferred findings
Review notes
/on…=in URLs and code is removed; thejavascript:rewrite can flip quote parity on crafted input. None runs script; all are covered by the structure-preserving rewrite in the next PR.Exploratory QA
Functional,
make-pdf generatethrough gstack's own browser on owned fixtures. Status: pass. An ordinary document with quotes printed (exit 0, 16,699-byte PDF), and the encoded-quoteonloadcaption plus a raw<svg/onload>sent 0 requests (main: 2). Aside not run.Documentation
Status: current. No documentation changes were needed for this branch.
Scope: the committed diff a256d15..e1f0632 (make-pdf/src/render.ts, make-pdf/src/smartypants.ts, make-pdf/test/render.test.ts, changelog.d/make-pdf-quote-entities-stay-in-attributes.md). There were no staged, unstaged or new files. The change is an internal security fix: quote entities stay inside attributes and the sanitizer is stricter. No flag, command or output format changed.
Documentation health:
Coverage debt: no user doc describes how make-pdf sanitizes raw HTML. This audit leaves that gap as it is and does not fill it.
Diagram drift: none.
Agent notes
Found in GEVA-584's Opus 5.5 runs on main b5eb401 (control agent gstack-c); its blind verifier spotted the
onerrorbypass. The handoff patch kept entities in tags by splitting on<[^>]*>, which still decodes them wherever that split disagrees with the browser, so this PR moves the decode into smartypants' curly-only text pass instead. The opening-quote and SVGstroke-widthfixes from the same handoff touch other functions and follow in a separate PR.gstack-issue-linksread and'in commit messages as issue references #10 and #39; they are not, so no issue links are listed. Lane GSTA-832 for GStack Minder.Approvals
Approved: yes (record r-e53fc3f88688). The full approval record stays private.
Plan: exempt: bug fix (R65)
Plan check: exempt bug fix
REVIEW_LOOP: passes=3 blocking_found=4 deferred=1 noted=5 fixed=3 scope=frozen open=2 dispatches=12
Gate edits: none detected (gate scan tagged 0 hunks at e1f0632)
Ruled note: make-pdf/src/render.ts:228:outside-voice at e1f0632 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-23T23:45:55Z) at 2026-11-23T23:45:55.468Z: over-match on contrived input; no script runs; 0 of 609 tracked Markdown files change; structure-preserving fix follows in the NUL hotfix PR (approval a-9de1cacca5e4)
Ruled note: make-pdf/src/render.ts:233:outside-voice at e1f0632 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-23T23:45:55Z) at 2026-11-23T23:45:55.587Z: over-match on contrived input; no script runs; 0 of 609 tracked Markdown files change; structure-preserving fix follows in the NUL hotfix PR (approval a-2d25d95c29fa)