Centralize sanitization of untrusted GitHub response fields - #3114
Merged
SamMorrowDrums merged 2 commits intoAug 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Centralizes sanitization of user-authored GitHub response fields while preserving patch and file-content fidelity.
Changes:
- Sanitizes text in shared minimal-response converters.
- Covers raw search and discussion response paths.
- Adds broad sanitization regression tests.
Show a summary per file
| File | Description |
|---|---|
pkg/github/minimal_types.go |
Sanitizes shared minimal response types. |
pkg/github/issues.go |
Sanitizes raw issue-search results. |
pkg/github/pullrequests.go |
Removes redundant call-site sanitization. |
pkg/github/search_utils.go |
Sanitizes raw PR search results. |
pkg/github/discussions.go |
Sanitizes discussion titles, bodies, and comments. |
pkg/github/projects.go |
Sanitizes project status bodies. |
pkg/github/sanitize_coverage_test.go |
Adds converter and fidelity regression tests. |
pkg/github/discussions_test.go |
Tests malicious discussion content. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 8/8 changed files
- Comments generated: 3
- Review effort level: Balanced
Sanitization was previously applied ad hoc at a handful of tool call sites (GetIssue, GetPullRequest, ListPullRequests) rather than in the shared convertToMinimal* converters, so equivalent user-authored text returned by other tools (issue comments, PR reviews, review comments, releases, commit messages, discussions, project item titles) was returned unsanitized. - Apply sanitize.Sanitize inside the convertToMinimal* helpers in minimal_types.go for issue/PR titles and bodies, issue comments, PR reviews, review comments, releases, commit messages, and project item content titles. This is the single, shared conversion point used by nearly every read tool, so fixing it there covers get/list issues, pull requests, comments, reviews, review comments, releases, commits, and project items consistently. - Add a sanitizeIssueTitleAndBody helper and use it for the two response paths that marshal a raw *github.Issue directly instead of a Minimal* type: search_issues (SearchIssueResult.MarshalJSON) and search_pull_requests (searchHandler). - Sanitize discussion titles/bodies/comments (list_discussions, get_discussion, get_discussion_comments), which previously had no sanitization at all, via a new newMinimalDiscussionComment constructor and inline fixes. - Sanitize project status update bodies. - Remove the now-redundant scattered sanitize calls in GetIssue, GetPullRequest, and ListPullRequests now that the shared converters sanitize on their own. Patches, diffs, and raw file contents are intentionally left untouched to preserve fidelity. Adds table-driven regression tests covering every touched converter, the search_issues/search_pull_requests raw-passthrough paths, and a fidelity check that patches/diffs are not altered. Fixes #3106 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Route every MinimalIssueRef/MinimalPullRequestRef construction through shared constructors that sanitize the user-authored title, so issue_dependency_read, issue_dependency_write and find_duplicate no longer forward raw issue titles. Also sanitize the get_file_blame commit message headline, after truncation so the headline is still cut at the author's real first line break. Extends the sanitization regression suite with the project status update body, both ref constructors and the dependency ref, and adds tool-level regression tests for find_duplicate and get_file_blame. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SamMorrowDrums
force-pushed
the
sammorrowdrums-issue-3106-apply-consistent-sanitization-to-untrust-18354a
branch
from
August 19, 2026 12:54
4f4917b to
af11e05
Compare
SamMorrowDrums
deleted the
sammorrowdrums-issue-3106-apply-consistent-sanitization-to-untrust-18354a
branch
August 19, 2026 13:20
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.
Problem
Sanitization (
pkg/sanitize.Sanitize) was applied ad hoc at a handful of tool call sites (GetIssue,GetPullRequest,ListPullRequests) instead of in the shared conversion layer. As a result, equivalent user-authored text returned by other tools — issue comments, PR reviews, review comments, releases, commit messages, discussions, project item titles — was returned completely unsanitized, andsearch_issues/search_pull_requestsbypassed the converters entirely by marshaling raw*github.Issueobjects.Fix
Moved sanitization into the shared
convertToMinimal*converters inpkg/github/minimal_types.go, which is the single conversion point used by nearly every read tool. This one change now consistently covers:get_commit,list_commits,search_commits,list_pull_request_commits, file-commit responses, workflow run head commit)Additional targeted fixes for paths that don't go through
minimal_types.go:sanitizeIssueTitleAndBodyhelper used bysearch_issues(SearchIssueResult.MarshalJSON) andsearch_pull_requests(searchHandler), the only two tools that marshal a raw*github.Issuedirectly.list_discussions,get_discussion,get_discussion_comments) previously had no sanitization at all — fixed via a newnewMinimalDiscussionCommentconstructor and inline fixes.Removed the now-redundant scattered sanitize calls in
GetIssue,GetPullRequest, andListPullRequestssince the shared converters handle it now.Fidelity preserved: patch/diff fields (
MinimalCommitFile.Patch,MinimalPRFile.Patch) and raw file contents are intentionally left untouched — these must remain byte-exact so patches stay applicable and code isn't corrupted.Testing
pkg/github/sanitize_coverage_test.go: table-driven regression tests covering every converter touched above, thesearch_issues/search_pull_requestsraw-passthrough paths, the shared helper's nil-safety, and a fidelity check confirming patches/diffs are not altered.Test_GetDiscussiontable indiscussions_test.go.script/lint— 0 issues.go test -race ./...(viascript/test) — all packages pass.script/generate-docsproducing no diff).Fixes #3106