MCP config_git_set exposes the GitHub token on the func subprocess command line
维护者通常 2 天内回复
评估
调研方向
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 小时
- 30 天内合并 PR
- 50
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
knative/func 的其他 Issue
-
help wanted kind/good-first-issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 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
-
难度 2/5 1-3 小时 新手友好度 82/100
kagent-dev/kagent#3792 ·
维护者通常 1 天内回复
-
ai-driven-qa bug claude Minor
难度 2/5 1-3 小时 新手友好度 68/100
linagora/cozy-stack#5374 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
google/certificate-transparency-go#1859 ·
维护者通常 1 天内回复
-
[Bug]: gate 缺失未关闭bug
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 64/100
newrelic/newrelic-cli#1958 ·
维护者通常 1 天内回复