MCP config_git_set exposes the GitHub token on the func subprocess command line

オープン
#4,188 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@anjalirj27 がすでに取り組んでいます。

2026年11月23日 から。

  • #4189 @anjalirj27 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
github, go
領域
security

調査の方向性

Start in pkg/mcp/tools_config_git.go, where ConfigGitSetInput.Args appends --gh-access-token around line 77, and follow how the MCP executor builds the func subprocess command line and environment. The reporter's proposed direction is an ExecuteEnv hook so the token travels as FUNC_GH_ACCESS_TOKEN rather than a flag; the two Python scripts in the issue reproduce the leak without any real credential. Verify with go test -race ./pkg/mcp/... and make check. Note that PR #4189 is already open against this issue, so coordinate before starting.

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

説明

What happens

The MCP server's config_git_set tool passes the GitHub access token to the func subprocess as a command-line flag:

func config git set ... --gh-access-token <token>

On Linux any local user can read another process's command line (/proc/<pid>/cmdline, ps), so the token is visible to other users on the same machine for as long as the subprocess runs. This matters on shared hosts such as CI runners and multi-user servers.

Code: pkg/mcp/tools_config_git.go, line 77 (ConfigGitSetInput.Args appends --gh-access-token).

Preconditions: MCP write mode (FUNC_ENABLE_MCP_WRITE=true), an agent calling config_git_set with gh_access_token, and another user on the same Linux host.

How to reproduce
  1. In a golang:1.26 Linux container, build func from main and put it on PATH.
  2. func create -l go /tmp/demo-fn
  3. As a second, unprivileged user, run watch_proc.py (below). It reads /proc/*/cmdline and prints any command line containing --gh-access-token.
  4. As the first user, run python3 repro_token_leak.py /tmp/demo-fn. It starts func mcp start and calls config_git_set 20 times with a fake token.
  5. The second user's watcher prints the full fake token. In my run it caught the token in 25 processes.

The recording below shows these steps. Only a fake token was used.

https://github.com/user-attachments/assets/14f006d6-417f-45f5-a0bf-d43709fe3d71

Proposed fix

The CLI already reads every flag from a FUNC_-prefixed environment variable, so FUNC_GH_ACCESS_TOKEN works today. Setting it in the subprocess environment instead of passing the flag keeps the token out of the command line; a process's environment is only readable by the same user and root.

I have a fix ready (an ExecuteEnv method on the MCP executor, plus regression tests that fail on current code and pass with the fix; go test -race ./pkg/mcp/... and make check pass). I'd like to work on this. Could it be assigned to me?

watch_proc.py
#!/usr/bin/env python3
"""
Watch every process on the machine and print any whose command line contains
'--gh-access-token'. Linux / WSL only (reads /proc, which every user can read).

This needs no special access: run it as an ordinary user, ideally a DIFFERENT
user from the one running the MCP server, to show the token is visible to
others. Stop with Ctrl+C.
"""
import os
import signal
import time

seen = set()
print("Watching all processes for '--gh-access-token' (Ctrl+C to stop)...", flush=True)
try:
    while True:
        for pid in os.listdir("/proc"):
            if not pid.isdigit() or pid in seen:
                continue
            try:
                with open(f"/proc/{pid}/cmdline", "rb") as f:
                    args = f.read().split(b"\0")
            except OSError:
                continue  # process already gone
            cmd = " ".join(a.decode(errors="replace") for a in args if a)
            if "--gh-access-token" in cmd:
                seen.add(pid)
                print(f"{time.strftime('%H:%M:%S')}  pid {pid}: {cmd}", flush=True)
except KeyboardInterrupt:
    signal.signal(signal.SIGINT, signal.SIG_IGN)  # a second Ctrl+C won't cut the summary
    print(f"\nStopped. Saw the token in {len(seen)} process(es).")
repro_token_leak.py
#!/usr/bin/env python3
"""
Reproduce: the func MCP server's config_git_set tool puts the GitHub access
token on the command line of the `func` subprocess, where any local user can
read it (e.g. with `ps`).

This script acts like an AI agent: it starts `func mcp start`, then calls the
config_git_set tool with a FAKE token. Watch the process list in a second
terminal while it runs.

Usage:
    python3 repro_token_leak.py /absolute/path/to/a/function

Requirements: `func` on your PATH (the MCP server runs the `func` it finds on
PATH), Python 3. Uses only the standard library.
"""
import json
import os
import subprocess
import sys

FAKE_TOKEN = "ghp_FAKE_DEMO_TOKEN_1234567890"  # never use a real token here
ROUNDS = 20  # repeat the call so the short-lived subprocess is easy to spot


def main():
    if len(sys.argv) != 2 or not os.path.isabs(sys.argv[1]):
        sys.exit("usage: repro_token_leak.py /absolute/path/to/a/function")
    path = sys.argv[1]

    env = dict(os.environ, FUNC_ENABLE_MCP_WRITE="true")  # config_git_set needs write mode
    server = subprocess.Popen(
        ["func", "mcp", "start"],
        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
        env=env, text=True,
    )

    def send(msg):
        server.stdin.write(json.dumps(msg) + "\n")
        server.stdin.flush()

    def wait_for(msg_id):
        while True:
            line = server.stdout.readline()
            if not line:
                sys.exit("MCP server exited unexpectedly")
            msg = json.loads(line)
            if msg.get("id") == msg_id:
                return msg

    # MCP handshake, as every MCP client does.
    send({"jsonrpc": "2.0", "id": 0, "method": "initialize", "params": {
        "protocolVersion": "2025-06-18", "capabilities": {},
        "clientInfo": {"name": "repro", "version": "0"}}})
    info = wait_for(0)["result"]["serverInfo"]
    send({"jsonrpc": "2.0", "method": "notifications/initialized"})
    print(f"Connected to MCP server: {info['name']} {info['version']}")
    print(f"Calling config_git_set {ROUNDS} times with fake token {FAKE_TOKEN}\n")

    for i in range(1, ROUNDS + 1):
        send({"jsonrpc": "2.0", "id": i, "method": "tools/call", "params": {
            "name": "config_git_set",
            "arguments": {
                "path": path,
                "git_url": "https://github.com/example/demo-fn",
                "git_branch": "main",
                "gh_access_token": FAKE_TOKEN,
                # Only record the git settings: no pipeline files, no cluster,
                # no webhook. Keeps every call fast, repeatable and harmless.
                "config_local": False,
                "config_cluster": False,
                "config_remote": False,
            }}})
        result = wait_for(i)["result"]
        status = "error" if result.get("isError") else "ok"
        print(f"  call {i:2d}: {status}")

    server.stdin.close()
    server.wait(timeout=30)
    print("\nDone. Check the other terminal for the token in the process list.")


if __name__ == "__main__":
    main()
主要言語
Go
スター
366
フォーク
231
平均マージ
2日 23時間
マージ済み PR(30日)
50

環境構築

はじめの一歩

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

knative/func のほかの issue

knative/func の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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