Repository navigation
fix(docs): prevent JSON-LD script breakout - #78670
Conversation
Protect custom and inherited blog structured data from script termination while preserving JSON values. Add production-build regressions for docs and blog metadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
There was a problem hiding this comment.
🟡 Changes recommended
Playwright discovers the JSON-LD Node test, causing its hooks and Astro build to run outside Playwright’s lifecycle and reporting.
1 open issue
What changed in this PR
Hardens the docs site's JSON-LD against script-element breakout by escaping literal < characters after serialization without changing parsed values.
Changes:
- Protects structured data generated by the custom head and inherited from the blog plugin.
- Leaves ordinary JavaScript head entries unchanged.
- Adds production-build regression tests for hostile metadata, nested blog values, and homepage structured data.
| File | Description |
|---|---|
docs/tests/jsonld-security.test.mjs |
Adds escaping and production-build security regressions. |
docs/src/lib/json-ld.js |
Provides the serialized JSON-LD escaping helper. |
docs/src/components/CustomHead.astro |
Applies escaping to custom and inherited JSON-LD blocks. |
docs/package.json |
Adds the dedicated test:jsonld command. |
Review effort: Max (adaptive)
| import assert from "node:assert/strict"; | ||
| import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; | ||
| import { join } from "node:path"; | ||
| import { after, before, test } from "node:test"; |
|
🎉 This pull request is included in a new release. Release: |

Summary
JSON serialization alone does not make structured data safe inside an HTML script element. Published page metadata could terminate the JSON-LD blocks emitted by the docs head or inherited from the blog plugin.
Escape literal
<characters after serialization for both paths, preserving the original values when JSON is parsed. Ordinary JavaScript head entries are unchanged.Add production-build regressions covering docs and blog titles/descriptions independently, nested blog author/tag values, and homepage structured data.
Validation
npm --prefix docs run test:jsonld: 6 passed using the real Astro/Starlight build and locked blog plugin.make agent-report-progress: passed; impacted Go tests skipped because no Go files changed.make agent-report-progress-no-test: passed on the final candidate.Limitation
Threat-detector effectiveness remains unverified. The separate local detector probe was blocked by its credential/network isolation review and was not executed. No GitHub Actions workflow was dispatched.