fix(github): sanitize bodies on all issue and pull request read paths - #3035
fix(github): sanitize bodies on all issue and pull request read paths#3035SashaMIT wants to merge 5 commits into
Conversation
Issue and PR title/body responses are passed through sanitize.Sanitize (invisible-glyph, BiDi, HTML-tag and code-fence-metadata stripping), but the two remaining body-bearing read paths were not: - convertToMinimalIssueComment returned comment bodies verbatim, so every comment read delivered raw attacker-controlled content. - GetSubIssues marshalled sub-issues (title+body) verbatim. A hostile comment could therefore carry hidden prompt-injection content (invisible Unicode tag block, BiDi overrides) straight into the model context, bypassing the control applied on every sibling path. Apply the same sanitize.Sanitize call in both places.
…read paths Full Sanitize runs bluemonday, which escapes entities and silently truncates a fenced code block at the first '<'. Comment and review bodies are the most code-dense fields the server returns, so applying it there corrupts content delivered to the model. Add sanitize.FilterBody (invisible characters + code fence metadata, no HTML filtering) and use it for issue comment, PR review, PR review comment and sub-issue bodies. Titles keep the full Sanitize treatment. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b8dd0f23-2c6e-47c1-bad5-c1d0c9361f13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b8dd0f23-2c6e-47c1-bad5-c1d0c9361f13
The remaining read paths still ran bodies through the HTML filter, which escapes entities and truncates a fenced code block at the first '<'. Bodies on issue_read and pull_request_read are as code-dense as comment bodies, so they get the same treatment. Titles keep the full Sanitize pass. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b8dd0f23-2c6e-47c1-bad5-c1d0c9361f13
IrynaKulakova
left a comment
There was a problem hiding this comment.
Approving. The read-path gap is real and the fix is now consistent across every body-bearing path.
Note that this PR was iterated on during review: bodies use sanitize.FilterBody (invisible characters + code-fence metadata) rather than the full Sanitize, because the bluemonday pass silently truncates a fenced code block at the first <. Titles still get the full treatment. Test coverage was added at the sanitize unit level, per-converter, and end-to-end through the issue_read handler.
Disclosure: I pushed the follow-up commits (57d4875, 9915997, 585519e) to this branch, so a second maintainer eye on those would be good before merge.
|
Thanks Iryna. Glad the FilterBody vs full Sanitize cut is the one that keeps fenced code intact, and that the tests now cover unit, converter, and the issue_read path. Appreciate you landing the follow-ups on the branch. Happy to wait on a second maintainer eye before merge. |
Problem
The server sanitizes issue/PR titles and bodies on read, but two body-bearing read paths missed the control entirely:
convertToMinimalIssueComment(minimal_types.go) — comment bodies were returned verbatim, so everyget_commentsread delivered raw attacker-controlled text.GetSubIssues(issues.go) — sub-issue titles/bodies were marshalled verbatim.A hostile comment or sub-issue could carry hidden prompt-injection payloads — invisible Unicode tag blocks or BiDi overrides, invisible to a human reviewer but legible to the model — straight into the context window.
Fixing that surfaced a second problem in the paths that were covered.
sanitize.Sanitizeends withFilterHTMLTags, which runs bluemonday over the content:Bodies are the most code-dense fields the server returns — generics, JSX, shell redirects, diffs. Truncating a fenced code block at the first
<corrupts the content delivered to the model, which is worse than the injection vector it defends against.Fix
Add
sanitize.FilterBody— invisible-character filtering plus code-fence metadata stripping, without the HTML pass — and use it for every body on a read path:convertToMinimalIssueComment)convertToMinimalPullRequestReview)convertToMinimalReviewComment)GetSubIssues)GetIssue,fragmentToMinimalIssue)GetPullRequest, PR list)Titles keep the full
sanitize.Sanitizetreatment: they are single-line and not code-bearing, so HTML filtering is safe there. Lockdown-mode filtering is untouched and orthogonal.The injection payloads that motivated this — Unicode tag characters (U+E0000 block), BiDi overrides, zero-width joiners, and hidden code-fence info strings — are all still stripped; only the HTML pass is dropped for bodies.
Testing
TestSanitizeBodyinpkg/sanitize: tag characters, BiDi overrides and hidden fence metadata are stripped; angle brackets, fenced code containing<, and HTML-like markup survive.pkg/github/minimal_types_test.go: per-converter coverage for comment, review, review-comment and GraphQL issue-fragment bodies.Test_GetSubIssues_Sanitization: end-to-end through theissue_readhandler.script/lintandscript/testpass. No tool schema or response-shape change, so toolsnaps and README are unaffected.