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

オープン 初心者向け
#3,191 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
security

調査の方向性

まず、ツール向けのガイダンスを記載したサーバーのドキュメントを探してください。issue にはファイルもテストも指定されていません。ワークスペースのルート配下でツールから提供されたパスを解決し、絶対パスと .. によるルート外への逸脱を拒否する方法を、例とともに説明するセクションを追加してください。ドキュメントにパスの包含に関するガイダンスが含まれれば完了です。任意の helper resolveWithin(root, p) は別途、範囲と設計を定める必要があります。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
13.8k
フォーク
2.5k
平均マージ
6日 23時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/typescript-sdk のほかの issue

modelcontextprotocol/typescript-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。