Strip data-* attributes in stripDangerousAttributes#31714
Closed
Copilot wants to merge 3 commits into
Closed
Conversation
Co-authored-by: szabta89 <1330202+szabta89@users.noreply.github.com>
data-* attributes on GFM-allowed tags (e.g. <span data-x="...">) are invisible in rendered GitHub Markdown but passed through the sanitizer verbatim, making them a hidden injection channel. Add data-[a-z0-9_-]+ (with /gi flag for case-insensitivity) to the stripDangerousAttributes regex alongside the existing on* and style clauses. Also update JSDoc and inline comments to document the rationale, and add 8 regression tests. Co-authored-by: szabta89 <1330202+szabta89@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix stripDangerousAttributes to strip data-* custom attributes
Strip May 12, 2026
data-* attributes in stripDangerousAttributes
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a hidden prompt-injection channel by removing data-* HTML attributes from otherwise-allowed GFM tags during sanitization, and adds regression tests to prevent reintroduction.
Changes:
- Extend
stripDangerousAttributesto stripdata-*attributes in addition toon*andstyle. - Add regression tests for
data-*stripping across quoting forms, valueless attributes, and mixed safe/dangerous attributes. - Update Dependabot workflows to derive the Docker socket path from
DOCKER_HOSTwhen building the MCP gatewaydocker runcommand.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/sanitize_content_core.cjs | Extends dangerous-attribute stripping logic to remove data-* attributes and updates inline documentation/comments. |
| actions/setup/js/sanitize_content.test.cjs | Adds regression tests ensuring data-* attributes are removed from allowed tags while preserving safe attributes. |
| .github/workflows/dependabot-worker.lock.yml | Uses DOCKER_HOST (when it’s a unix socket/path) to select the socket file mounted into the MCP gateway container. |
| .github/workflows/dependabot-campaign.lock.yml | Same DOCKER_HOST-aware socket-path logic for the campaign workflow’s MCP gateway container. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
actions/setup/js/sanitize_content_core.cjs:689
- This note says the pattern intentionally uses
\s+to require whitespace before attribute names, but the actual regex uses[\s/]+, which can also match a bare/(as described a few lines below). To avoid confusion for future maintainers, consider updating this note to refer to[\s/]+/ “whitespace-or-slash” instead of just\s+.
* Note: `\s+` (requiring at least one whitespace before the attribute name) is
* intentional — HTML attributes are always separated from the tag name and from
* each other by at least one whitespace character. Using `\s*` would risk false
* matches inside tag names (e.g. matching "ong" inside "strong").
- Files reviewed: 4/4 changed files
- Comments generated: 2
| // Using [\s/]+ (instead of \s+) also strips dangerous attributes that are immediately | ||
| // preceded by a "/" with no space — e.g. the malformed <img/onerror=alert(1) src=x>. | ||
| return tagContent.replace(/[\s/]+(?:on\w+|style)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>"'`]*))?/gi, ""); | ||
| return tagContent.replace(/[\s/]+(?:on\w+|style|data-[a-z0-9_-]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>"'`]*))?/gi, ""); |
| const result = sanitizeContent('<span data-x="INJECT">text</span>'); | ||
| expect(result).toBe("<span>text</span>"); | ||
| }); | ||
|
|
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.
Bug Fix
What was the bug?
data-*attributes on GFM-allowed tags (e.g.<span data-x="...">) silently passed throughstripDangerousAttributesunchanged. They produce zero visible output in rendered Markdown, so adversarial content embedded in them is undetectable by human reviewers but delivered verbatim to the agent — a structurally equivalent hidden channel to HTML comments and zero-width-space splits, both of which are already neutralized.How did you fix it?
sanitize_content_core.cjs— Extended thestripDangerousAttributesregex to includedata-[a-z0-9_-]+alongside the existingon\w+andstyleclauses. The existing/giflag handles case-insensitivity, making theA-Zrange in the character class redundant. Updated JSDoc and call-site comment to document the rationale.Testing
sanitize_content.test.cjs— Added 8 regression tests covering: double-quoted, single-quoted, unquoted, and bare (valueless)data-*attributes; multipledata-*attributes on one tag;data-*combined withon*/style;data-*alongside preserved safe attributes; and case-insensitive matching (DATA-X).