Repository navigation
security(fix): decode XML entities in a single pass (CodeQL js/double-escaping) - #391
Conversation
…-escaping)
Both diagram body-line decoders expanded entities with a chain of
.replaceAll() calls starting at '&'. That is not the inverse of
escapeXml: text containing a literal "<" escapes to "&lt;" and
the chain decoded it back to "<" — the second pass re-consumed the '&'
the first pass produced. CodeQL flagged both sites as js/double-escaping
(high).
Add unescapeXml next to escapeXml in diagram-template.ts: one regex pass
over an entity table, so a produced '&' can never be re-read as the start
of another entity, and unknown entities are left untouched. Use it in
validateRenderedDiagram and in the int spec, removing the duplicated
chain from both.
Lock the property with a round-trip assertion over inputs that already
look like entities ('<not-a-tag>', '&lt;', '&&&'), which fails
against the old chain.
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Deployment failed with the following error: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe diagram template adds an exported ChangesXML decoding
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: dependency version conflict. Check your lock file or package.json. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…r adoption, template a11y (#409) Brings main level with dev (137 commits). Headline items: - the component wall no longer crops blocks: per-breakpoint zoom pins the twins' inner layout width at 1280px (#392), and the 640-1023px band gets a 256px frame plus a widened fade (#399). Production was cutting content-quote, content-feature-media and content-feature-split by 88/79/78px on a tablet; measured on the live site, not inferred. Three viewport tests now assert the fit so a curated-at-one-width regression cannot recur silently. - prettier is adopted: config matched to the house style (#402), the tree formatted, and format:check gated in test:release and the CI lint step (#408). - template a11y and layout fixes (#394, #398, #404), consent gate split by provider (#400), axe now waits for the consent banner (#405), CodeQL double-escaping fix (#391). Tree is identical to dev by construction: branched from dev, reparented onto main, so the diff is exactly the main..dev delta with no squash-divergence conflicts.
Summary
Clears the two open high-severity CodeQL
js/double-escapingalerts (#5, #6) — the genuine findings surfaced during the PR #388 promote review, as distinct from the long-known URL-substring false positive.The bug
escapeXmlencodes&first, which is correct. Both decoders, however, also expanded&first via a.replaceAll()chain — so they were not its inverse:escapeXml<not-a-tag>&lt;not-a-tag&gt;<not-a-tag>❌The first pass turns
&into&, and the next pass re-reads that fresh&as the start of<. Any diagram body line containing literal entity text decoded to the wrong string, and the length checks downstream measured the wrong value. It's the standard double-unescaping defect — benign here because the input is our own committed SVG, but it's a real correctness bug and the class is XSS-adjacent wherever the input isn't trusted.The fix
Add
unescapeXmlbesideescapeXmlintools/blog/visual-system/diagram-template.ts: one regex pass over an entity table, so a&the decoder produces can never be re-consumed, and unknown or partial entities ( , a bare& 5) pass through untouched. Both call sites now use it, deleting the duplicated chain from each.A round-trip assertion locks the property, using inputs that already look like entities (
<not-a-tag>,&lt;,&&&) — it fails against the old chain.Validation
vitest run tests/int/blog-visual-system.int.spec.ts— 73 passedtsc --noEmitclean,eslintclean on both filesgrepconfirms zero&-first chains remain intools/,tests/,src/,payload-components/🤖 Generated with Claude Code
Summary by CodeRabbit