get_file_contents directory listings put tokenised private-repo download URLs in model context

Open
#3,748 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
github, go

Research direction

Start in pkg/github/repositories.go and trace how directory entries are rendered, including how the fields parameter uses fileContentFieldEnum. Check the large-file message that explicitly tells callers to use the download URL. Done when directory listings omit or strip the tokenized URL by default, explicit field requests can still include it, and the large-file path retains its download URL.

Written by the indexing model from the issue text.

Description

enhancement
Describe the feature or problem you’d like to solve

Low-severity hardening suggestion (not a vulnerability report).

In v2.1.0, get_file_contents on a directory of a private repository returns, for every entry, a download_url of the form https://raw.githubusercontent.com/<owner>/<repo>/<sha>/<path>?token=… in the model-visible text. That URL fetches the file with no other authentication for a short time (a few minutes in my tests, and it worked more than once); without the token parameter it returns 404.

The REST contents API itself returns this URL, so the server is passing it through rather than creating it. But for a directory listing the model rarely needs a credential-bearing URL for every file, and it is the one field in the listing that grants access on its own. If an agent is steered by untrusted content (prompt injection) into copying it somewhere public, anyone can fetch that private file for the next few minutes. The marginal risk is small, since a hijacked agent could also read and paste the file, but the URL is a bearer credential the model doesn’t need.

For files of 1 MB or more, get_file_contents also tells the model to use the download URL (pkg/github/repositories.go, the File %s is too large to display … Use the download URL message), which is a reasonable place to keep it.

Proposed solution
  • Omit download_url (or strip its token query parameter) from directory listings by default; callers that need it can already ask for it through the fields parameter (download_url is in fileContentFieldEnum).
  • Keep the explicit download URL for the large-file path, where the model is meant to use it.

Benefit: one less bearer credential in model context and in client logs/transcripts, with no loss of function.

Example prompts or workflows (for tools/toolsets only)
  1. "List the files in src/ of my private repo" — needs names, paths, sizes, SHAs; not per-file signed URLs.
  2. "Find the config file in this private repo and summarise it" — the agent lists the directory, then reads the file through the tool, never through the raw URL.
  3. Agent transcripts and MCP client logs that record tool output no longer contain short-lived access tokens for private files.
Additional context
  • Reproduced on v2.1.0 (ghcr.io/github/github-mcp-server@sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a), --read-only, fine-grained read-only token, against a throwaway private repo in an org I own. A src/ listing returned 4 entries, all with tokenised download_urls; an unauthenticated GET of one returned 200, the same URL without the token 404.
  • Found during an independent, AI-assisted review of v2.1.0; reproduced by hand.
Dominant language
Go
Stars
34.2k
Forks
5.3k
Avg merge
5d 18h
Merged PRs (30d)
13

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/github-mcp-server

All issues in github/github-mcp-server

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.