Security guidance: tool-input file paths written without containment (arbitrary file write class)

Offen Anfängerfreundlich
#3,191 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
65/100
Issue-Typ
Dokumentation
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
security

Rechercherichtung

Beginne damit, die Serverdokumentation für Tool-Hinweise zu finden; das Issue nennt weder eine Datei noch einen Test. Füge einen Abschnitt hinzu, der erklärt, wie von Tools bereitgestellte Pfade innerhalb eines Workspace-Stammverzeichnisses aufgelöst und absolute Pfade sowie ..-Ausbrüche zurückgewiesen werden, mit einem Beispiel. Erledigt ist die Aufgabe, wenn die Dokumentation die Hinweise zur Pfadbegrenzung enthält; der optionale Helper resolveWithin(root, p) würde einen separaten Umfang und Entwurf erfordern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

v1 v2

While auditing the MCP server ecosystem (1,654 npm-backed servers
deep-scanned with MCP-aware CodeQL taint analysis), I found a recurring,
independently-rediscovered class: a tool declares a path-shaped input
(output_path, local_path, output_dir) as an unconstrained string and passes
it to path.resolve()/path.join() then fs.writeFileSync, with no workspace
containment. Because an MCP tool caller is frequently an LLM acting on
untrusted content, the path is attacker-influenced via indirect prompt
injection - no human chooses it. Result: arbitrary file write and
destructive overwrite (authorized_keys, rc files, configs).

Prevalence in the scanned sample is material (path-traversal flows present
in a measurable share of servers; aggregate scorecard available). Several
affected servers even shipped a containment helper for one sink and left
the tool-input writes raw.

This is a server-author footgun, not an SDK bug, but the SDK is the natural
place to prevent it at scale. Proposed, in order of increasing
intrusiveness:

  1. A short "Writing files from a tool safely" section in the server-author
    docs, with the containment pattern (resolve against a workspace root,
    reject absolute and ".." escapes).
  2. Optionally, an exported resolveWithin(root, p) helper so authors do not
    hand-roll it (several who did, got it wrong).

I can open the docs PR with the guidance text and an example. Full
methodology and the CodeQL pack that finds this are public at
github.com/stillmarcus24/mcp-security-research. No unfixed server is named;
findings are under coordinated disclosure.

Vorherrschende Sprache
TypeScript
Sterne
13.8k
Forks
2.5k
Ø Merge
6 T. 23 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/typescript-sdk

Alle Issues in modelcontextprotocol/typescript-sdk

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.