Skip to content

Centralize sanitization of untrusted GitHub response fields - #3114

Merged
SamMorrowDrums merged 2 commits into
mainfrom
sammorrowdrums-issue-3106-apply-consistent-sanitization-to-untrust-18354a
Aug 19, 2026
Merged

SamMorrowDrums merged 2 commits into
mainfrom
sammorrowdrums-issue-3106-apply-consistent-sanitization-to-untrust-18354a

Conversation

@SamMorrowDrums

@SamMorrowDrums SamMorrowDrums commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

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, 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).

Fixes #3106

Acknowledgments

Thanks @yotampe-pluto, @tonghuaroot, @gurudeepmallam-cmd, @nicoleman0, and @Gal3m for the reports that led to this hardening.

Copilot AI balanced review requested due to automatic review settings August 19, 2026 12:31