fix: harden against confirmed review findings - #2
Conversation
Make _strip_tags quote-aware so a raw `>` inside a quoted attribute of raw HTML in an image description cannot terminate the tag early and break out of the generated alt="…" attribute (injection-prone unbalanced HTML). Add a regression test covering double/single-quoted attributes and a nested <img>. Document in SECURITY.md that output is NOT sanitized: raw HTML and javascript:/data: URLs pass through verbatim per CommonMark, so rendering untrusted markdown into a live page is a stored-XSS risk that callers must sanitize themselves. Co-Authored-By: Claude <noreply@anthropic.com>
|
🤖 Independent Claude review: Verdict: Ready to mark for review. Adversarial second look — no blocking correctness/security issue found. Verified (by hand-tracing bytes, not just re-running the author's tests):
Non-blocking nits (optional):
|
|
Code review (opus, static — verify CI): SHIP-WITH-NITS Fixes a real HTML-attribute breakout: image alt text flows into Nit: |
From an automated multi-agent review (personal-context#62); implemented + verified by Claude Code.
Two confirmed hardening findings against the public repo. Each fix was reproduced on the current source, fixed, and re-verified; a regression test was added. Built and tested against Mojo
1.0.0b3.dev2026070506.1. (security) image-alt breakout in
_strip_tags— FIXEDRaw inline HTML passes through verbatim (CommonMark). When such HTML appears in an image description,
_strip_tagsscanned for the tag-closing>without honoring quoted attribute values. A raw>inside a quoted attribute (e.g.title="a>b") terminated the tag early, and the trailing bytes leaked into — and broke out of — the generatedalt="…"attribute, emitting unbalanced, injection-prone HTML.Repro / evidence (input
):<p><img src="/i.png" alt="b">x" /></p>← the>closes the img early;x"leaks as markup<p><img src="/i.png" alt="x" /></p>← matches CommonMark referenceFix: made the tag scan in
_strip_tagsquote-aware (skips over"/'-delimited attribute values). Regression testtest_image_alt_raw_html_gt_no_breakoutcovers double-quoted, single-quoted, and nested-<img>cases.2. (security/doc) output is not sanitized — DOCUMENTED in SECURITY.md
Raw HTML and
javascript:/data:URLs pass through verbatim (spec-compliant), but SECURITY.md previously framed the only risk as crashes/hangs — a stored-XSS trap for callers. Added an explicit "Output is NOT sanitized" section: rendering untrusted markdown into a live page is a stored-XSS risk and callers must sanitize (e.g. DOMPurify-equivalent) themselves. Behavior is intentionally unchanged (spec compliance preserved); documented rather than changed. A safe-mode/sanitizing flag was considered but left out to keep the change low-risk and API-stable.pixi pin
Checked: the repo's
pixi.tomlalready pinsmojo = ">=1.0.0b3.dev2026070506,<2", which solves correctly (pixi installsucceeds). The>=1.0.0b3sort-below-nightlies bug does not exist here — no change needed.Verification
Overlap note
A separate agent is editing README.md and CHANGELOG.md in parallel PRs; this PR deliberately does not touch either file. Based off
origin/main.