Security hardening: sanitize MCP App CSP domains - #17192
Merged
Merged
Conversation
Filter out domain values containing whitespace, ";" or "," before interpolating them into the generated Content-Security-Policy so a malicious value cannot inject additional sources, directives, or policies. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Validate each server-supplied CSP domain by parsing it as an absolute URL, keeping only https/wss origins, and re-checking the decoded origin. This closes an encoding bypass where a percent-encoded separator (e.g. "%3B") passes a raw-string filter but decodes back into ";" downstream, and additionally rejects non-https/wss schemes and bare keyword sources. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Lock base-uri and form-action to 'none' so a sandboxed app cannot retarget <base href> or submit forms to an arbitrary destination. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…P sources Drop a bare "*" host (which allows every origin, defeating the scheme allowlist) and reject quote/backtick characters that survive URL parsing and could break out of an HTML attribute the policy is embedded in. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gr2m
approved these changes
Jul 14, 2026
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getMCPAppCSPinpackages/react/src/mcp-apps/sandbox.tsinterpolated server-supplied domain values (connectDomains,resourceDomains,frameDomains) straight into the Content-Security-Policy string. Since CSP directives are;-separated and sources are whitespace-separated, a value could break out of its directive and inject arbitrary sources, directives, or policies.This adds a
sanitizeCSPSourcesfilter that drops any value containing whitespace,;, or,before it reaches the policy string.Behavior
Happy path:
https://api.example.com) pass through unchanged into their directives.Unhappy path:
https://api.example.test; script-src-elem https://attacker.exampleis dropped entirely, so no extra directive appears.,(which could split into a second policy) is dropped.Tests
Added
sandbox.test.tscovering valid passthrough and injection-attempt rejection.🤖 Generated with Claude Code