fix: widen sanitizeAIOutput to cover HTML and @mentions (Bug #29)#49
Open
fix: widen sanitizeAIOutput to cover HTML and @mentions (Bug #29)#49
Conversation
Why: wave-1 LLM and Security agents flagged the previous one-pattern
sanitiser (workflow commands only) as too narrow. AI model output is
embedded directly in PR comments — an attacker controlling the diff
content could inject `<img onerror>`, `<script>`, or mass `@team`
mentions that GitHub renders as HTML/notifications.
What:
- Escape `<` and `>` to HTML entities so injected tags render as text.
- De-fang `@username` and `@org/team` patterns by inserting U+200B
(zero-width space) after the @ sigil. The @ remains visible to
humans but GitHub's mention parser no longer matches.
- Source uses `` escape (not the literal char) to satisfy
`no-irregular-whitespace` and so the intent is visible to maintainers.
- Email-like text (foo@example.com) is preserved — not a GitHub
username pattern, so the @-alphanumeric regex doesn't match it.
Test plan:
- 3 new tests in __tests__/integration/ai-review.test.js cover the
three new behaviours (HTML escape, mention de-fang, email preserved).
- npm test → 837 pass (was 834).
- npm run lint → clean.
Risk: low — defence-in-depth on AI output. The strict-JSON contract +
verdict-from-findings already prevent the model from controlling the
verdict; this widens what gets neutralised in free-text fields too.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
sanitizeAIOutputfrom a single workflow-command regex to a four-stage filter: workflow commands, HTML angle-bracket escaping, and@mentionde-fanging via U+200B.docs/agent-fleet/bugs.md(flagged by wave-1 LLM + Security agents).escape (not the literal char) sono-irregular-whitespacepasses and the de-fang is visible to future maintainers.Why this matters
AI output is embedded directly in PR comments. The previous sanitiser only handled
::workflow-command::injection; it left HTML tags and@org/teammentions intact, which GitHub will happily render as markup or convert into mass notifications.Test plan
npm test→ 837 pass (3 new tests added)npm run lint→ clean<script>renders as text and@octocatdoesn't pingRisk
Low. Defence-in-depth on free-text fields. The strict-JSON contract +
computeVerdictalready prevent the model from steering the verdict; this widens what's neutralised in summary/claim text.🤖 Generated with Claude Code