Skip to content

Commit 1ca9b46

Browse files
committed
fix(github): sanitize PR review and discussion bodies on read paths
Issue/PR title and body reads already run through sanitize.Sanitize. PR review bodies, review-thread comments, and Discussion title/body/comments still returned raw attacker-controlled text into the model context. Apply the same sanitize control on those sibling read paths. Clean content is unchanged; lockdown filtering is untouched.
1 parent eb4c099 commit 1ca9b46

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

pkg/github/discussions.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/github/github-mcp-server/pkg/ifc"
1010
"github.com/github/github-mcp-server/pkg/inventory"
11+
"github.com/github/github-mcp-server/pkg/sanitize"
1112
"github.com/github/github-mcp-server/pkg/scopes"
1213
"github.com/github/github-mcp-server/pkg/translations"
1314
"github.com/github/github-mcp-server/pkg/utils"
@@ -99,7 +100,7 @@ type WithCategoryNoOrder struct {
99100
func fragmentToDiscussion(fragment NodeFragment) *github.Discussion {
100101
return &github.Discussion{
101102
Number: github.Ptr(int(fragment.Number)),
102-
Title: github.Ptr(string(fragment.Title)),
103+
Title: github.Ptr(sanitize.Sanitize(string(fragment.Title))),
103104
HTMLURL: github.Ptr(string(fragment.URL)),
104105
CreatedAt: &github.Timestamp{Time: fragment.CreatedAt.Time},
105106
UpdatedAt: &github.Timestamp{Time: fragment.UpdatedAt.Time},
@@ -360,8 +361,8 @@ func GetDiscussion(t translations.TranslationHelperFunc) inventory.ServerTool {
360361
// like ListDiscussions and GetDiscussionComments).
361362
response := map[string]any{
362363
"number": int(d.Number),
363-
"title": string(d.Title),
364-
"body": string(d.Body),
364+
"title": sanitize.Sanitize(string(d.Title)),
365+
"body": sanitize.Sanitize(string(d.Body)),
365366
"url": string(d.URL),
366367
"closed": bool(d.Closed),
367368
"isAnswered": bool(d.IsAnswered),
@@ -522,14 +523,14 @@ func GetDiscussionComments(t translations.TranslationHelperFunc) inventory.Serve
522523
for _, c := range q.Repository.Discussion.Comments.Nodes {
523524
comment := MinimalDiscussionComment{
524525
ID: fmt.Sprintf("%v", c.ID),
525-
Body: string(c.Body),
526+
Body: sanitize.Sanitize(string(c.Body)),
526527
IsAnswer: bool(c.IsAnswer),
527528
ReplyTotalCount: c.Replies.TotalCount,
528529
}
529530
for _, r := range c.Replies.Nodes {
530531
comment.Replies = append(comment.Replies, MinimalDiscussionComment{
531532
ID: fmt.Sprintf("%v", r.ID),
532-
Body: string(r.Body),
533+
Body: sanitize.Sanitize(string(r.Body)),
533534
IsAnswer: bool(r.IsAnswer),
534535
})
535536
}
@@ -564,7 +565,7 @@ func GetDiscussionComments(t translations.TranslationHelperFunc) inventory.Serve
564565
for _, c := range q.Repository.Discussion.Comments.Nodes {
565566
comments = append(comments, MinimalDiscussionComment{
566567
ID: fmt.Sprintf("%v", c.ID),
567-
Body: string(c.Body),
568+
Body: sanitize.Sanitize(string(c.Body)),
568569
IsAnswer: bool(c.IsAnswer),
569570
})
570571
}

pkg/github/minimal_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func convertToMinimalPullRequestReview(review *github.PullRequestReview) Minimal
645645
m := MinimalPullRequestReview{
646646
ID: review.GetID(),
647647
State: review.GetState(),
648-
Body: review.GetBody(),
648+
Body: sanitize.Sanitize(review.GetBody()),
649649
HTMLURL: review.GetHTMLURL(),
650650
User: convertToMinimalUser(review.GetUser()),
651651
CommitID: review.GetCommitID(),
@@ -1909,7 +1909,7 @@ func convertToMinimalReviewThread(thread reviewThreadNode) MinimalReviewThread {
19091909

19101910
func convertToMinimalReviewComment(c reviewCommentNode) MinimalReviewComment {
19111911
m := MinimalReviewComment{
1912-
Body: string(c.Body),
1912+
Body: sanitize.Sanitize(string(c.Body)),
19131913
Path: string(c.Path),
19141914
Author: string(c.Author.Login),
19151915
HTMLURL: c.URL.String(),

0 commit comments

Comments
 (0)