FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(sanitize): preserve visible Markdown content by SamMorrowDrums · Pull Request #3177 · github/github-mcp-server · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (9) .md  (3) .mod  (1) .sum  (1) No extension  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions go.mod
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.12.1
github.com/yosida95/uritemplate/v3 v3.0.2
github.com/yuin/goldmark v1.8.5
golang.org/x/oauth2 v0.36.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSW
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.8.5 h1:r6N5afV5qj/5S4UTch8agZHJ8UxNCMwX7WjkkJam2NA=
github.com/yuin/goldmark v1.8.5/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/discussions.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func GetDiscussion(t translations.TranslationHelperFunc) inventory.ServerTool {
response := map[string]any{
"number": int(d.Number),
"title": sanitize.Sanitize(string(d.Title)),
"body": sanitize.Sanitize(string(d.Body)),
"body": sanitize.Content(string(d.Body)),
"url": string(d.URL),
"closed": bool(d.Closed),
"isAnswered": bool(d.IsAnswered),
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/discussions_test.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func Test_GetDiscussion(t *testing.T) {
expected: map[string]any{
"number": float64(1),
"title": sanitizedText,
"body": sanitizedText,
"body": sanitizedContentText,
"url": "https://github.com/owner/repo/discussions/1",
"closed": false,
"isAnswered": false,
Expand Down
20 changes: 19 additions & 1 deletion pkg/github/issues.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,9 @@ func GetSubIssues(ctx context.Context, client *github.Client, deps ToolDependenc
subIssues = filteredSubIssues
}

for _, subIssue := range subIssues {
sanitizeSubIssueTitleAndBody(subIssue)
}
r, err := json.Marshal(subIssues)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
Expand Down Expand Up @@ -1708,6 +1711,7 @@ func AddSubIssue(ctx context.Context, client *github.Client, owner string, repo
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to add sub-issue", resp, body), nil
}

sanitizeSubIssueTitleAndBody(subIssue)
r, err := json.Marshal(subIssue)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
Expand Down Expand Up @@ -1739,6 +1743,7 @@ func RemoveSubIssue(ctx context.Context, client *github.Client, owner string, re
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to remove sub-issue", resp, body), nil
}

sanitizeSubIssueTitleAndBody(subIssue)
r, err := json.Marshal(subIssue)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
Expand Down Expand Up @@ -1788,6 +1793,7 @@ func ReprioritizeSubIssue(ctx context.Context, client *github.Client, owner stri
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to reprioritize sub-issue", resp, body), nil
}

sanitizeSubIssueTitleAndBody(subIssue)
r, err := json.Marshal(subIssue)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
Expand Down Expand Up @@ -1998,7 +2004,19 @@ func sanitizeIssueTitleAndBody(issue *github.Issue) {
issue.Title = github.Ptr(sanitize.Sanitize(*issue.Title))
}
if issue.Body != nil {
issue.Body = github.Ptr(sanitize.Sanitize(*issue.Body))
issue.Body = github.Ptr(sanitize.Content(*issue.Body))
}
}

func sanitizeSubIssueTitleAndBody(issue *github.SubIssue) {
if issue == nil {
return
}
if issue.Title != nil {
issue.Title = github.Ptr(sanitize.Sanitize(*issue.Title))
}
if issue.Body != nil {
issue.Body = github.Ptr(sanitize.Content(*issue.Body))
}
}

Expand Down
33 changes: 33 additions & 0 deletions pkg/github/issues_test.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -5922,6 +5922,26 @@ func Test_GetSubIssues(t *testing.T) {
},
},
}
unsafeSubIssues := []*github.Issue{
{
Number: github.Ptr(125),
Title: github.Ptr(maliciousText),
Body: github.Ptr(maliciousText),
State: github.Ptr("open"),
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/125"),
User: &github.User{Login: github.Ptr("user3")},
},
}
sanitizedSubIssues := []*github.Issue{
{
Number: github.Ptr(125),
Title: github.Ptr(sanitizedText),
Body: github.Ptr(sanitizedContentText),
State: github.Ptr("open"),
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/125"),
User: &github.User{Login: github.Ptr("user3")},
},
}

tests := []struct {
name string
Expand Down Expand Up @@ -5966,6 +5986,19 @@ func Test_GetSubIssues(t *testing.T) {
expectError: false,
expectedSubIssues: mockSubIssues,
},
{
name: "sanitizes sub-issue titles and bodies",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
GetReposIssuesSubIssuesByOwnerByRepoByIssueNumber: mockResponse(t, http.StatusOK, unsafeSubIssues),
}),
requestArgs: map[string]any{
"method": "get_sub_issues",
"owner": "owner",
"repo": "repo",
"issue_number": float64(42),
},
expectedSubIssues: sanitizedSubIssues,
},
{
name: "successful sub-issues listing with empty result",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
Expand Down
24 changes: 12 additions & 12 deletions pkg/github/minimal_types.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type MinimalDiscussionComment struct {
func newMinimalDiscussionComment(id string, body string, isAnswer bool) MinimalDiscussionComment {
return MinimalDiscussionComment{
ID: id,
Body: sanitize.Sanitize(body),
Body: sanitize.Content(body),
IsAnswer: isAnswer,
}
}
Expand Down Expand Up @@ -797,7 +797,7 @@ func convertToMinimalPullRequestReview(review *github.PullRequestReview) Minimal
m := MinimalPullRequestReview{
ID: review.GetID(),
State: review.GetState(),
Body: sanitize.Sanitize(review.GetBody()),
Body: sanitize.Content(review.GetBody()),
HTMLURL: review.GetHTMLURL(),
User: convertToMinimalUser(review.GetUser()),
CommitID: review.GetCommitID(),
Expand All @@ -815,7 +815,7 @@ func convertToMinimalIssue(issue *github.Issue) MinimalIssue {
m := MinimalIssue{
Number: issue.GetNumber(),
Title: sanitize.Sanitize(issue.GetTitle()),
Body: sanitize.Sanitize(issue.GetBody()),
Body: sanitize.Content(issue.GetBody()),
State: issue.GetState(),
StateReason: issue.GetStateReason(),
Draft: issue.GetDraft(),
Expand Down Expand Up @@ -926,7 +926,7 @@ func fragmentWithoutFieldValuesToMinimalIssue(fragment issueFragmentWithoutField
m := MinimalIssue{
Number: int(fragment.Number),
Title: sanitize.Sanitize(string(fragment.Title)),
Body: sanitize.Sanitize(string(fragment.Body)),
Body: sanitize.Content(string(fragment.Body)),
State: string(fragment.State),
Comments: int(fragment.Comments.TotalCount),
CreatedAt: fragment.CreatedAt.Format(time.RFC3339),
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func convertToMinimalIssuesResponseWithoutFieldValues(fragment issueQueryFragmen
func convertToMinimalIssueComment(comment *github.IssueComment) MinimalIssueComment {
m := MinimalIssueComment{
ID: comment.GetID(),
Body: sanitize.Sanitize(comment.GetBody()),
Body: sanitize.Content(comment.GetBody()),
HTMLURL: comment.GetHTMLURL(),
User: convertToMinimalUser(comment.GetUser()),
AuthorAssociation: comment.GetAuthorAssociation(),
Expand Down Expand Up @@ -1064,7 +1064,7 @@ func convertToMinimalFileContentResponse(resp *github.RepositoryContentResponse)

m.Commit = &MinimalFileCommit{
SHA: resp.Commit.GetSHA(),
Message: sanitize.Sanitize(resp.Commit.GetMessage()),
Message: sanitize.Content(resp.Commit.GetMessage()),
HTMLURL: resp.Commit.GetHTMLURL(),
}

Expand All @@ -1085,7 +1085,7 @@ func convertToMinimalPullRequest(pr *github.PullRequest) MinimalPullRequest {
m := MinimalPullRequest{
Number: pr.GetNumber(),
Title: sanitize.Sanitize(pr.GetTitle()),
Body: sanitize.Sanitize(pr.GetBody()),
Body: sanitize.Content(pr.GetBody()),
State: pr.GetState(),
Draft: pr.GetDraft(),
Merged: pr.GetMerged(),
Expand Down Expand Up @@ -1794,7 +1794,7 @@ func newMinimalCommitFromCore(sha, htmlURL string, commit *github.Commit, author

if commit != nil {
minimalCommit.Commit = &MinimalCommitInfo{
Message: sanitize.Sanitize(commit.GetMessage()),
Message: sanitize.Content(commit.GetMessage()),
}

if commit.Author != nil {
Expand Down Expand Up @@ -1997,7 +1997,7 @@ func convertToMinimalPullRequestCommits(commits []*github.RepositoryCommit) []Mi
}

if commit.Commit != nil {
minimalCommit.Message = sanitize.Sanitize(commit.Commit.GetMessage())
minimalCommit.Message = sanitize.Content(commit.Commit.GetMessage())
minimalCommit.Author = convertToMinimalCommitAuthor(commit.Commit.Author)
}

Expand Down Expand Up @@ -2036,7 +2036,7 @@ func convertToMinimalRelease(release *github.RepositoryRelease) MinimalRelease {
ID: release.GetID(),
TagName: release.GetTagName(),
Name: sanitize.Sanitize(release.GetName()),
Body: sanitize.Sanitize(release.GetBody()),
Body: sanitize.Content(release.GetBody()),
HTMLURL: release.GetHTMLURL(),
Prerelease: release.GetPrerelease(),
Draft: release.GetDraft(),
Expand Down Expand Up @@ -2092,7 +2092,7 @@ func convertToMinimalWorkflowRun(workflowRun *github.WorkflowRun) MinimalWorkflo

if headCommit := workflowRun.GetHeadCommit(); headCommit != nil && headCommit.GetMessage() != "" {
minimalRun.HeadCommit = &MinimalWorkflowRunHeadCommit{
Message: sanitize.Sanitize(headCommit.GetMessage()),
Message: sanitize.Content(headCommit.GetMessage()),
}
}

Expand Down Expand Up @@ -2277,7 +2277,7 @@ func convertToMinimalReviewThread(thread reviewThreadNode) MinimalReviewThread {

func convertToMinimalReviewComment(c reviewCommentNode) MinimalReviewComment {
m := MinimalReviewComment{
Body: sanitize.Sanitize(string(c.Body)),
Body: sanitize.Content(string(c.Body)),
Path: string(c.Path),
Author: string(c.Author.Login),
HTMLURL: c.URL.String(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/projects.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func convertToMinimalStatusUpdate(node statusUpdateNode) MinimalProjectStatusUpd

return MinimalProjectStatusUpdate{
ID: fmt.Sprintf("%v", node.ID),
Body: sanitize.Sanitize(derefString(node.Body)),
Body: sanitize.Content(derefString(node.Body)),
Status: derefString(node.Status),
CreatedAt: node.CreatedAt.Time.Format(time.RFC3339),
StartDate: derefString(node.StartDate),
Expand Down
Loading

Back | FazBrowse Home | New Git URL