You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Centralize sanitization of untrusted GitHub response fields - #3114
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, and search_issues/search_pull_requests bypassed the converters entirely by marshaling raw *github.Issue objects.
Fix
Moved sanitization into the shared convertToMinimal* converters in pkg/github/minimal_types.go, which is the single conversion point used by nearly every read tool. This one change now consistently covers:
Issue/PR titles and bodies (REST and project-item paths)
Issue comments
PR reviews and review comments
Releases (name + body)
Commit messages (get_commit, list_commits, search_commits, list_pull_request_commits, file-commit responses, workflow run head commit)
Project item content titles and project pull-request-ref titles
Additional targeted fixes for paths that don't go through minimal_types.go:
Added a sanitizeIssueTitleAndBody helper used by search_issues (SearchIssueResult.MarshalJSON) and search_pull_requests (searchHandler), the only two tools that marshal a raw *github.Issue directly.
Discussions (list_discussions, get_discussion, get_discussion_comments) previously had no sanitization at all — fixed via a new newMinimalDiscussionComment constructor and inline fixes.
Project status update bodies.
Removed the now-redundant scattered sanitize calls in GetIssue, GetPullRequest, and ListPullRequests since 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
Added pkg/github/sanitize_coverage_test.go: table-driven regression tests covering every converter touched above, the search_issues/search_pull_requests raw-passthrough paths, the shared helper's nil-safety, and a fidelity check confirming patches/diffs are not altered.
Added a malicious-payload case to the existing Test_GetDiscussion table in discussions_test.go.
script/lint — 0 issues.
go test -race ./... (via script/test) — all packages pass.
No tool schemas changed, so no toolsnap or README/docs regeneration was required (verified via script/generate-docs producing no diff).
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
Acknowledgments
Thanks @yotampe-pluto, @tonghuaroot, @gurudeepmallam-cmd, @nicoleman0, and @Gal3m for the reports that led to this hardening.