Fix HTML injection in code block titles#18866
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18866Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18866" |
There was a problem hiding this comment.
Pull request overview
Fixes HTML injection through fenced code-block language metadata by escaping the displayed title at the rendering boundary.
Changes:
- HTML-encodes code-block titles before rendering.
- Adds regression coverage for an SVG event-handler payload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Aspire.Dashboard/Model/Markdown/HighlightedCodeBlockRenderer.cs |
Escapes untrusted title text. |
tests/Aspire.Dashboard.Tests/Markdown/MarkdownProcessorTests.cs |
Verifies malicious language metadata is encoded. |
Tests selector (audit mode)The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement. 7 / 100 test projects · 4 jobs, from 2 changed files. Selected test projects (7 / 100)
Selected jobs (4)
How these were chosen — grouped by what changed🔧 📦 affected project 🧪 Job reasons
Selection computed for commit |
Description
Fenced code block language metadata was written directly into the code block title while the rendered Markdown was later trusted as HTML. A crafted language value could therefore escape the title element and inject arbitrary HTML even though raw HTML is disabled in the Markdown pipeline.
This change HTML-encodes the visible code block title at the renderer boundary. The existing attribute and code body rendering behavior is unchanged.
Security considerations
This closes an HTML injection path for untrusted Markdown by treating fenced code block language metadata as untrusted input and encoding it at the HTML sink. A regression test covers a compact SVG event-handler payload. A formal security review has not yet been completed.
Validation:
Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?