From 63909765e6cdbb85695a2f977ee1cf400c4a4d6e Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:28:27 -0500 Subject: [PATCH 1/9] fix(repos): omit download URLs from directory listings --- pkg/github/repositories.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index b884f4888d..fce9192b48 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -1007,7 +1007,7 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool Required: []string{"owner", "repo"}, } schema.Properties["fields"] = fieldsSchemaProperty( - "Subset of fields to return for each entry when the path is a directory. If omitted, all fields are returned. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.", + "Subset of fields to return for each entry when the path is a directory. 'download_url' is omitted by default; request it explicitly in 'fields' when needed. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.", fileContentFieldEnum, ) @@ -1192,7 +1192,7 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool } else if dirContent != nil { // file content or file SHA is nil which means it's a directory filtered := false - var payload any = dirContent + var payload any if len(fields) > 0 { filteredEntries, err := filterEachField(dirContent, fields) if err != nil { @@ -1200,6 +1200,8 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool } payload = filteredEntries filtered = true + } else { + payload = cloneDirectoryEntriesWithoutDownloadURLs(dirContent) } r, err := json.Marshal(payload) if err != nil { @@ -1226,6 +1228,22 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool ) } + +// cloneDirectoryEntriesWithoutDownloadURLs returns directory entries without +// download URLs while leaving the API response untouched. +func cloneDirectoryEntriesWithoutDownloadURLs(entries []*github.RepositoryContent) []*github.RepositoryContent { + cloned := make([]*github.RepositoryContent, len(entries)) + for i, entry := range entries { + if entry == nil { + continue + } + entryCopy := *entry + entryCopy.DownloadURL = nil + cloned[i] = &entryCopy + } + return cloned +} + // recordDirContentsFieldsUsage emits fields telemetry for a get_file_contents // directory listing. sentBytes is the size of the payload actually returned. func recordDirContentsFieldsUsage(ctx context.Context, deps ToolDependencies, full []*github.RepositoryContent, filtered bool, sentBytes int) { From 6b10e35fc152f3464d3252a2a842f2daad3b2a1a Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:28:30 -0500 Subject: [PATCH 2/9] test(repos): cover directory download URL omission --- pkg/github/repositories_test.go | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 9b40c932ff..41d1d579ba 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -925,6 +925,54 @@ func Test_GetFileContents_DirectoryFieldFiltering(t *testing.T) { assert.NotContains(t, textContent.Text, "download_url") } + +// Test_GetFileContents_DirectoryOmitsDownloadURLByDefault verifies that directory +// listings omit bearer-token URLs from the model-visible text by default. +func Test_GetFileContents_DirectoryOmitsDownloadURLByDefault(t *testing.T) { + const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" + result, requests := runRepositoryReadFixture(t, repositoryReadFixture{ + contents: []*github.RepositoryContent{{ + Type: new("file"), + Name: new(".env.example"), + Path: new(".env.example"), + SHA: new("abc123"), + Size: new(42), + HTMLURL: new("https://github.com/owner/private-repo/blob/main/.env.example"), + DownloadURL: new(tokenizedURL), + }}, + }, map[string]any{ + "owner": "owner", + "repo": "private-repo", + "path": "src/", + "sha": strings.Repeat("a", 40), + }) + + require.False(t, result.IsError) + assert.Equal(t, 1, requests) + textContent := getTextResult(t, result) + assert.NotContains(t, textContent.Text, "download_url") + assert.NotContains(t, textContent.Text, "GHSAT0AAAAA_SECRET_TOKEN") + assert.Contains(t, textContent.Text, ".env.example") + assert.Contains(t, textContent.Text, "html_url") +} + +func TestCloneDirectoryEntriesWithoutDownloadURLs(t *testing.T) { + const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" + entry := &github.RepositoryContent{Name: new(".env.example"), DownloadURL: new(tokenizedURL)} + original := []*github.RepositoryContent{entry, nil} + + cloned := cloneDirectoryEntriesWithoutDownloadURLs(original) + + require.Len(t, cloned, 2) + require.NotNil(t, cloned[0]) + assert.NotSame(t, entry, cloned[0]) + assert.Nil(t, cloned[0].DownloadURL) + assert.Equal(t, ".env.example", cloned[0].GetName()) + assert.Nil(t, cloned[1]) + require.NotNil(t, entry.DownloadURL) + assert.Equal(t, tokenizedURL, *entry.DownloadURL) +} + func Test_GetFileContents_DirectoryFieldsTelemetry(t *testing.T) { mockDirContent := []*github.RepositoryContent{ { From 3656a1a28bf915d6a6ca56bbd2db3b7674a7c377 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:28:33 -0500 Subject: [PATCH 3/9] test(repos): cover directory download URL protocol compatibility --- pkg/github/typed_compatibility_test.go | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/github/typed_compatibility_test.go b/pkg/github/typed_compatibility_test.go index d1e68a6b1f..fa21b3ec27 100644 --- a/pkg/github/typed_compatibility_test.go +++ b/pkg/github/typed_compatibility_test.go @@ -268,6 +268,43 @@ func TestTypedCompatibilityDirectoryProjection(t *testing.T) { } } + +// TestTypedCompatibilityDirectoryDownloadURL verifies that download URLs are +// omitted from default directory listings across protocols and remain opt-in. +func TestTypedCompatibilityDirectoryDownloadURL(t *testing.T) { + tool := GetFileContents(translations.NullTranslationHelper) + for _, protocol := range []string{"2025-11-25", inventory.ProtocolVersionMultiRoundTrip} { + t.Run(protocol+"/default", func(t *testing.T) { + session := connectTypedSearchClient(t, tool, typedRepositoryDeps(t), protocol) + result, err := session.CallTool(context.Background(), &mcp.CallToolParams{ + Name: tool.Tool.Name, Arguments: map[string]any{"owner": "owner", "repo": "repo", "path": "directory"}, + }) + require.NoError(t, err) + require.False(t, result.IsError) + assert.NotContains(t, getTextResult(t, result).Text, "download_url") + if protocol == inventory.ProtocolVersionMultiRoundTrip { + require.NotNil(t, result.StructuredContent) + assert.NotContains(t, mustMarshalJSON(t, result.StructuredContent), "download_url") + } + }) + t.Run(protocol+"/explicit opt-in", func(t *testing.T) { + session := connectTypedSearchClient(t, tool, typedRepositoryDeps(t), protocol) + result, err := session.CallTool(context.Background(), &mcp.CallToolParams{ + Name: tool.Tool.Name, Arguments: map[string]any{ + "owner": "owner", "repo": "repo", "path": "directory", "fields": []string{"download_url"}, + }, + }) + require.NoError(t, err) + require.False(t, result.IsError) + assert.JSONEq(t, `[{"download_url":"https://raw.githubusercontent.com/owner/repo/main/file"}]`, getTextResult(t, result).Text) + if protocol == inventory.ProtocolVersionMultiRoundTrip { + require.NotNil(t, result.StructuredContent) + assert.Contains(t, mustMarshalJSON(t, result.StructuredContent), "download_url") + } + }) + } +} + func TestTypedCompatibilityBlameIFC(t *testing.T) { for _, private := range []bool{false, true} { for _, protocol := range []string{"2025-11-25", inventory.ProtocolVersionMultiRoundTrip} { From b68d59d356faa8312c6e9d405324d9d28a11c8d5 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:28:36 -0500 Subject: [PATCH 4/9] test(snapshots): update get_file_contents schema snapshot --- pkg/github/__toolsnaps__/get_file_contents.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/github/__toolsnaps__/get_file_contents.snap b/pkg/github/__toolsnaps__/get_file_contents.snap index fa845c7d50..460e150fc7 100644 --- a/pkg/github/__toolsnaps__/get_file_contents.snap +++ b/pkg/github/__toolsnaps__/get_file_contents.snap @@ -20,7 +20,7 @@ "inputSchema": { "properties": { "fields": { - "description": "Subset of fields to return for each entry when the path is a directory. If omitted, all fields are returned. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.", + "description": "Subset of fields to return for each entry when the path is a directory. 'download_url' is omitted by default; request it explicitly in 'fields' when needed. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'.", "items": { "enum": [ "type", From f9aa7c4107912753ab69cfdc9fa224e65754374f Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:35:56 -0500 Subject: [PATCH 5/9] docs: document default download URL omission in tool catalog --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f297f7dd4..4c0291a259 100644 --- a/README.md +++ b/README.md @@ -1466,7 +1466,7 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - **get_file_contents** - Get file or directory contents - **OAuth Challenge Scopes**: `repo` - - `fields`: Subset of fields to return for each entry when the path is a directory. If omitted, all fields are returned. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'. (string[], optional) + - `fields`: Subset of fields to return for each entry when the path is a directory. 'download_url' is omitted by default; request it explicitly in 'fields' when needed. Ignored when the path is a single file. Use this to reduce response size when listing directories and you only need specific fields, e.g. just 'name' and 'type'. (string[], optional) - `owner`: Repository owner (username or organization) (string, required) - `path`: Path to file/directory (string, optional) - `ref`: Accepts optional git refs such as `refs/tags/{tag}`, `refs/heads/{branch}` or `refs/pull/{pr_number}/head` (string, optional) From 2122ca4b8de953ef56ca175f8f7c9efffc05b8cc Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:35:59 -0500 Subject: [PATCH 6/9] style: remove redundant blank line --- pkg/github/repositories.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/github/repositories.go b/pkg/github/repositories.go index fce9192b48..0fd5e3e1c3 100644 --- a/pkg/github/repositories.go +++ b/pkg/github/repositories.go @@ -1228,7 +1228,6 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool ) } - // cloneDirectoryEntriesWithoutDownloadURLs returns directory entries without // download URLs while leaving the API response untouched. func cloneDirectoryEntriesWithoutDownloadURLs(entries []*github.RepositoryContent) []*github.RepositoryContent { From 85f34edf2838ffdeeea3cf1c03adcc03c9c7de8a Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:36:02 -0500 Subject: [PATCH 7/9] style: remove redundant blank line --- pkg/github/repositories_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index 41d1d579ba..bc58fb5618 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -925,7 +925,6 @@ func Test_GetFileContents_DirectoryFieldFiltering(t *testing.T) { assert.NotContains(t, textContent.Text, "download_url") } - // Test_GetFileContents_DirectoryOmitsDownloadURLByDefault verifies that directory // listings omit bearer-token URLs from the model-visible text by default. func Test_GetFileContents_DirectoryOmitsDownloadURLByDefault(t *testing.T) { From 5efd1c6b5227de1f50291574e13fe7fd9e9941d1 Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:36:06 -0500 Subject: [PATCH 8/9] style: remove redundant blank line --- pkg/github/typed_compatibility_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/github/typed_compatibility_test.go b/pkg/github/typed_compatibility_test.go index fa21b3ec27..e74fbb5ce1 100644 --- a/pkg/github/typed_compatibility_test.go +++ b/pkg/github/typed_compatibility_test.go @@ -268,7 +268,6 @@ func TestTypedCompatibilityDirectoryProjection(t *testing.T) { } } - // TestTypedCompatibilityDirectoryDownloadURL verifies that download URLs are // omitted from default directory listings across protocols and remain opt-in. func TestTypedCompatibilityDirectoryDownloadURL(t *testing.T) { From 41b6081e2ad28f251bde4d5cf5cd3ef35f87b16d Mon Sep 17 00:00:00 2001 From: Thanh Nguyen <274720769+RealThanhNguyxn@users.noreply.github.com> Date: Sat, 14 Nov 2026 04:05:05 -0500 Subject: [PATCH 9/9] test(repos): annotate synthetic tokenized URL fixtures for gosec ./script/lint reported two G101 findings on the synthetic tokenized download URLs added for the default-omission coverage. Annotate both fixtures with the repository's nolint convention. - ./script/lint: 0 issues - ./script/test (go test -race ./...): all packages pass --- pkg/github/repositories_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/github/repositories_test.go b/pkg/github/repositories_test.go index bc58fb5618..3a045a0d38 100644 --- a/pkg/github/repositories_test.go +++ b/pkg/github/repositories_test.go @@ -928,7 +928,7 @@ func Test_GetFileContents_DirectoryFieldFiltering(t *testing.T) { // Test_GetFileContents_DirectoryOmitsDownloadURLByDefault verifies that directory // listings omit bearer-token URLs from the model-visible text by default. func Test_GetFileContents_DirectoryOmitsDownloadURLByDefault(t *testing.T) { - const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" + const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" //nolint:gosec // G101: Synthetic tokenized download URL fixture verifies default omission; it cannot authenticate. result, requests := runRepositoryReadFixture(t, repositoryReadFixture{ contents: []*github.RepositoryContent{{ Type: new("file"), @@ -956,7 +956,7 @@ func Test_GetFileContents_DirectoryOmitsDownloadURLByDefault(t *testing.T) { } func TestCloneDirectoryEntriesWithoutDownloadURLs(t *testing.T) { - const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" + const tokenizedURL = "https://raw.githubusercontent.com/owner/private-repo/main/.env.example?token=GHSAT0AAAAA_SECRET_TOKEN" //nolint:gosec // G101: Synthetic tokenized download URL fixture verifies default omission; it cannot authenticate. entry := &github.RepositoryContent{Name: new(".env.example"), DownloadURL: new(tokenizedURL)} original := []*github.RepositoryContent{entry, nil}