Skip to content

Fix HTML injection in code block titles#18866

Open
JamesNK wants to merge 1 commit into
mainfrom
fix/code-block-language-html-injection
Open

Fix HTML injection in code block titles#18866
JamesNK wants to merge 1 commit into
mainfrom
fix/code-block-language-html-injection

Conversation

@JamesNK

@JamesNK JamesNK commented Jul 23, 2026

Copy link
Copy Markdown
Member

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:

MarkdownProcessorTests: 26 passed, 0 failed

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@JamesNK
JamesNK requested a review from adamint as a code owner July 23, 2026 01:09
Copilot AI review requested due to automatic review settings July 23, 2026 01:09
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18866

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18866"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions

Copy link
Copy Markdown
Contributor

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)

Aspire.Cli.EndToEnd.Tests, Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Managed.Tests, Aspire.Playground.Tests

Selected jobs (4)

cli-starter, deployment-e2e, extension-e2e, polyglot


How these were chosen — grouped by what changed

🔧 src/Aspire.Dashboard/Model/Markdown/HighlightedCodeBlockRenderer.cs (changed source)
5 via the project graph: Aspire.Dashboard.Components.Tests, Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests (2 hops), Aspire.Managed.Tests (2 hops), Aspire.Playground.Tests (2 hops)

📦 affected project Aspire.Managed
1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Dashboard.Tests/Markdown/MarkdownProcessorTests.cs (changed test)
1 directly: Aspire.Dashboard.Tests

Job reasons

Job Triggered by
cli-starter • affected project Aspire.Managed
• selected test Aspire.Cli.EndToEnd.Tests
deployment-e2e affected project Aspire.Managed
extension-e2e src/Aspire.Dashboard/Model/Markdown/HighlightedCodeBlockRenderer.cs
• affected project Aspire.Dashboard
polyglot affected project Aspire.Managed

Selection computed for commit 10d0a49.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants