Skip to content

security(fix): decode XML entities in a single pass (CodeQL js/double-escaping) - #391

Merged
Ducksss merged 1 commit into
devfrom
fix/codeql-double-escaping
Jul 27, 2026
Merged

Ducksss merged 1 commit into
devfrom
fix/codeql-double-escaping

Conversation

@Ducksss

@Ducksss Ducksss commented Jul 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Clears the two open high-severity CodeQL js/double-escaping alerts (#5, #6) — the genuine findings surfaced during the PR #388 promote review, as distinct from the long-known URL-substring false positive.

The bug

escapeXml encodes & first, which is correct. Both decoders, however, also expanded & first via a .replaceAll() chain — so they were not its inverse:

input escapeXml old chain decodes to
&lt;not-a-tag&gt; &amp;lt;not-a-tag&amp;gt; <not-a-tag> ❌

The first pass turns &amp; into &, and the next pass re-reads that fresh & as the start of &lt;. 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 unescapeXml beside escapeXml in tools/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 (&nbsp;, a bare &amp 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 (&lt;not-a-tag&gt;, &amp;lt;, &&&) — it fails against the old chain.

Validation

  • vitest run tests/int/blog-visual-system.int.spec.ts — 73 passed
  • Full int suite — 372 passed, 1 skipped
  • tsc --noEmit clean, eslint clean on both files
  • grep confirms zero &amp;-first chains remain in tools/, tests/, src/, payload-components/

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved XML entity decoding in rendered diagrams, ensuring escaped text displays correctly.
    • Preserved unknown or incomplete entities instead of altering them unexpectedly.
    • Improved handling of diagram labels containing special characters and entity-like text.
  • Tests
    • Expanded coverage for XML escaping and decoding across varied text patterns.
    • Added validation to confirm rendered SVG text is decoded consistently.

…-escaping)

Both diagram body-line decoders expanded entities with a chain of
.replaceAll() calls starting at '&amp;'. That is not the inverse of
escapeXml: text containing a literal "&lt;" escapes to "&amp;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 ('&lt;not-a-tag&gt;', '&amp;lt;', '&&&'), which fails
against the old chain.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 27, 2026 18:35
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/ducksss-projects?upgradeToPro=build-rate-limit

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
payload-components-97bf Ready Ready Preview, Comment Jul 27, 2026 6:37pm

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a7461f59-8b8e-4d2b-be7e-e6840a2faf1f

📥 Commits

Reviewing files that changed from the base of the PR and between b5e7196 and 72167ac.

📒 Files selected for processing (2)
  • tests/int/blog-visual-system.int.spec.ts
  • tools/blog/visual-system/diagram-template.ts

📝 Walkthrough

Walkthrough

The diagram template adds an exported unescapeXml helper for supported XML entities, uses it during SVG validation, and adds integration tests covering inverse escaping and unchanged unknown or partial entities.

Changes

XML decoding

Layer / File(s) Summary
Shared XML decoding implementation
tools/blog/visual-system/diagram-template.ts
Adds unescapeXml using the shared entity map and applies it to extracted SVG body-line text during validation.
Decoder coverage and integration usage
tests/int/blog-visual-system.int.spec.ts
Tests inverse escaping, preserves unknown or partial entities, and updates rendered-text validation to use unescapeXml.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and validation, but it omits the required template sections for Verification, Registry Checklist, and Notes. Rewrite the PR description to match the template, including the Verification checkbox, all Registry Checklist items, and a Notes section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing XML entity decoding in a single pass.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codeql-double-escaping

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Ducksss
Ducksss merged commit d646903 into dev Jul 27, 2026
11 of 12 checks passed
@Ducksss
Ducksss deleted the fix/codeql-double-escaping branch July 27, 2026 19:25
Ducksss added a commit that referenced this pull request Jul 29, 2026
…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.

This branch was successfully deployed

1 active deployment
Preview – payload-components-97bf — 72167acd Deployed Jul 27, 2026 by vercel[bot]
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.

2 participants