@chroxy/server 0.10.0 → 0.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONFIG.md +602 -19
- package/README.md +2 -2
- package/hooks/claude-native-route-check.mjs +17 -0
- package/hooks/permission-hook.sh +416 -11
- package/package.json +20 -23
- package/sidecar/Dockerfile +1 -1
- package/sidecar/PROTOCOL.md +9 -1
- package/sidecar/agent.js +102 -10
- package/sidecar/package-lock.json +3 -3
- package/src/acp-config.js +206 -0
- package/src/acp-session.js +954 -0
- package/src/activity-registry.js +110 -5
- package/src/agent-connections.js +293 -0
- package/src/agent-control/client.js +1616 -0
- package/src/agent-control/events.js +547 -0
- package/src/agent-control/local-connection.js +275 -0
- package/src/agent-control/mcp-server.js +545 -0
- package/src/anthropic-compatible-config.js +29 -4
- package/src/anthropic-compatible-session.js +15 -6
- package/src/anthropic-openai-shim.js +0 -1
- package/src/archive-continuation.js +164 -0
- package/src/assistant-response.js +24 -0
- package/src/auth-probes.js +120 -13
- package/src/background-shell-tracker.js +27 -0
- package/src/base-session.js +1353 -41
- package/src/bearer-recheck.js +49 -0
- package/src/billing-budget.js +24 -1
- package/src/billing-class.js +40 -7
- package/src/binary-provenance-trust.js +101 -0
- package/src/bound-client-policy.js +279 -0
- package/src/built-in-tools/bash-exec.js +46 -7
- package/src/built-in-tools/file-ops.js +74 -9
- package/src/built-in-tools/tool-transforms.js +1113 -13
- package/src/byok-compose-state.js +6 -9
- package/src/byok-credentials.js +2 -3
- package/src/byok-mcp-client.js +1153 -20
- package/src/byok-mcp-config.js +1712 -8
- package/src/byok-mcp-fleet.js +416 -29
- package/src/byok-mcp-oauth-store.js +329 -0
- package/src/byok-mcp-oauth.js +635 -0
- package/src/byok-mcp-trust.js +257 -40
- package/src/byok-session.js +1400 -149
- package/src/byok-tool-executor.js +2681 -38
- package/src/byok-tools.js +9 -2
- package/src/channels/chroxy-channel-server.js +2 -3
- package/src/checkpoint-manager.js +96 -51
- package/src/chroxy-host-metadata.js +122 -0
- package/src/claude-channel-session.js +16 -10
- package/src/claude-model-catalog.js +131 -16
- package/src/claude-model-refresh.js +385 -0
- package/src/claude-model-request.js +103 -0
- package/src/claude-stream-parser.js +109 -3
- package/src/claude-tui/diagnostic-tail.js +83 -0
- package/src/claude-tui/form-driver.js +44 -7
- package/src/claude-tui/model-error.js +41 -0
- package/src/claude-tui/pty-driver.js +223 -60
- package/src/claude-tui/sanitize-question-payload.js +109 -0
- package/src/claude-tui/usage-limit.js +239 -0
- package/src/claude-tui-session.js +3611 -286
- package/src/claude-tui-tool-response.js +300 -0
- package/src/cli/agent-control-cmd.js +65 -0
- package/src/cli/config-cmd.js +6 -6
- package/src/cli/config-dir-cmd.js +234 -0
- package/src/cli/deploy-cmd.js +46 -11
- package/src/cli/doctor-cmd.js +7 -3
- package/src/cli/init-cmd.js +16 -17
- package/src/cli/providers-cmd.js +6 -6
- package/src/cli/schedule-cmd.js +804 -0
- package/src/cli/server-cmd.js +64 -2
- package/src/cli/service-cmd.js +70 -27
- package/src/cli/session-cmd.js +227 -74
- package/src/cli/shared.js +168 -14
- package/src/cli/tokens-cmd.js +212 -0
- package/src/cli/tunnel-cmd.js +256 -25
- package/src/cli/worktree-gc-cmd.js +2 -2
- package/src/cli-session.js +1117 -116
- package/src/cli.js +8 -0
- package/src/codex-app-server-client.js +36 -3
- package/src/codex-app-server-session.js +2108 -101
- package/src/codex-bundled-client.js +66 -0
- package/src/codex-model-catalog.js +548 -0
- package/src/codex-model-rejections.js +87 -0
- package/src/codex-native-resume.js +104 -0
- package/src/codex-protocol-capabilities.js +188 -0
- package/src/codex-session.js +571 -45
- package/src/config-dir-migration.js +444 -0
- package/src/config-dir.js +108 -0
- package/src/config.js +738 -52
- package/src/connection-authority.js +48 -0
- package/src/connection-info.js +5 -9
- package/src/connection-locality.js +60 -0
- package/src/container-liveness-monitor.js +189 -0
- package/src/continuation-metadata-worker.js +17 -0
- package/src/continuations.js +114 -0
- package/src/control-room/host-prune.js +5 -0
- package/src/control-room/integrations.js +23 -30
- package/src/control-room/skills-inventory.js +8 -3
- package/src/control-room/survey.js +32 -0
- package/src/conversation-scanner.js +40 -18
- package/src/conversation-scope.js +59 -39
- package/src/conversation-search.js +24 -22
- package/src/credential-store.js +279 -29
- package/src/daemon-commit.js +92 -0
- package/src/daemon-idle-state.js +171 -0
- package/src/daemon-update-status.js +314 -0
- package/src/dashboard-build.js +70 -0
- package/src/declared-status.js +90 -0
- package/src/deepseek-credentials.js +2 -3
- package/src/dev-preview.js +169 -182
- package/src/device-preferences.js +2 -2
- package/src/diagnostics.js +3 -0
- package/src/diff-parser.js +87 -0
- package/src/discord-credentials.js +2 -3
- package/src/docker-byok-pool.js +3 -1
- package/src/docker-byok-session.js +678 -78
- package/src/docker-image-allowlist.js +23 -1
- package/src/docker-sdk-session.js +188 -4
- package/src/docker-session.js +293 -10
- package/src/doctor.js +783 -66
- package/src/edited-input.js +264 -0
- package/src/environment-manager.js +175 -36
- package/src/environments/authority.js +95 -0
- package/src/environments/backends/container-claude-spawn.js +94 -0
- package/src/environments/backends/docker.js +39 -10
- package/src/environments/backends/k8s.js +58 -24
- package/src/environments/destroy-with-sessions.js +142 -0
- package/src/event-ingest.js +137 -14
- package/src/event-normalizer.js +363 -110
- package/src/external-session-registry.js +0 -0
- package/src/gemini-session.js +100 -7
- package/src/github-webhook.js +188 -4
- package/src/handler-utils.js +563 -62
- package/src/handlers/checkpoint-handlers.js +162 -20
- package/src/handlers/control-room-handlers.js +99 -29
- package/src/handlers/conversation-handlers.js +563 -25
- package/src/handlers/credential-handlers.js +43 -2
- package/src/handlers/daemon-update-handlers.js +81 -0
- package/src/handlers/evaluator-handlers.js +14 -1
- package/src/handlers/feature-handlers.js +186 -69
- package/src/handlers/file-handlers.js +101 -13
- package/src/handlers/github-webhook-handlers.js +204 -0
- package/src/handlers/input-handlers.js +689 -48
- package/src/handlers/orchestration-handlers.js +238 -0
- package/src/handlers/scheduler-handlers.js +584 -0
- package/src/handlers/session-handlers.js +546 -16
- package/src/handlers/session-pr-status-handlers.js +283 -0
- package/src/handlers/session-pr-threads-handlers.js +247 -0
- package/src/handlers/settings-handlers.js +822 -35
- package/src/handlers/skills-handlers.js +13 -4
- package/src/handlers/summarize-handlers.js +32 -1
- package/src/handlers/survey-throttle.js +380 -0
- package/src/handlers/token-handlers.js +11 -2
- package/src/health-proof.js +40 -0
- package/src/history-page.js +104 -0
- package/src/http-routes.js +286 -8
- package/src/ide/search.js +24 -6
- package/src/ide/symbols.js +20 -6
- package/src/input-context.js +117 -0
- package/src/instruction-policy-compiler.js +229 -0
- package/src/instruction-policy.js +250 -0
- package/src/jsonl-reader.js +309 -48
- package/src/jsonl-subprocess-session.js +122 -9
- package/src/keychain.js +160 -13
- package/src/logger.js +240 -31
- package/src/mailbox-route.js +11 -22
- package/src/message-wire.js +386 -0
- package/src/model-discovery.js +43 -3
- package/src/models.js +1276 -174
- package/src/notification-prefs.js +100 -10
- package/src/notifications/discord-billing-sink.js +22 -5
- package/src/notifications/discord-ci-sink.js +243 -0
- package/src/notifications/discord-webhook-client.js +71 -0
- package/src/notifications/discord-webhook-sink.js +82 -12
- package/src/notifications/expo-push-sink.js +85 -6
- package/src/notifications/ready-body.js +16 -5
- package/src/ollama-session.js +34 -2
- package/src/orchestration/build-manager.js +63 -0
- package/src/orchestration/decision-contract.js +245 -0
- package/src/orchestration/git-ops.js +381 -0
- package/src/orchestration/orchestration-manager.js +1342 -0
- package/src/orchestration/permission-gate.js +121 -0
- package/src/orchestration/role-prompts.js +136 -0
- package/src/orchestration/run-budget.js +81 -0
- package/src/orchestration/run-ledger.js +487 -0
- package/src/orchestration/run-model.js +206 -0
- package/src/orchestration/run-record.js +336 -0
- package/src/orchestration/run-report.js +194 -0
- package/src/orchestration/to-wire.js +201 -0
- package/src/orchestration/turn-driver.js +422 -0
- package/src/orphan-reaper.js +413 -0
- package/src/outgoing-policy.js +183 -0
- package/src/pairing.js +236 -12
- package/src/path-hash-trust-ledger.js +642 -25
- package/src/permission-audit.js +79 -3
- package/src/permission-deadlines.js +82 -0
- package/src/permission-floor.js +1770 -0
- package/src/permission-hook.js +180 -69
- package/src/permission-manager.js +1175 -94
- package/src/permission-mode-support.js +35 -0
- package/src/permission-resolver.js +174 -12
- package/src/permission-rule-store.js +411 -0
- package/src/permission-scope.js +43 -0
- package/src/platform.js +483 -23
- package/src/preview-ingress.js +54 -0
- package/src/preview-target.js +213 -0
- package/src/prompt-evaluator.js +34 -4
- package/src/provider-customization.js +180 -0
- package/src/providers.js +228 -6
- package/src/push.js +30 -4
- package/src/question-route-map.js +130 -0
- package/src/redaction.js +360 -8
- package/src/roster-broadcast.js +186 -0
- package/src/schedule-parser.js +311 -0
- package/src/scheduled-task-store.js +945 -0
- package/src/scheduler.js +1099 -0
- package/src/sdk-session.js +2374 -168
- package/src/server-cli/preview-shutdown.js +22 -0
- package/src/server-cli/push-notification-handler.js +11 -2
- package/src/server-cli/server-orchestrator.js +50 -4
- package/src/server-cli/tunnel-lifecycle-handler.js +3 -2
- package/src/server-cli-child.js +33 -18
- package/src/server-cli.js +760 -62
- package/src/server-identity.js +42 -14
- package/src/service.js +682 -53
- package/src/session-archive-limits.js +15 -0
- package/src/session-archive.js +1029 -0
- package/src/session-busy-state.js +72 -0
- package/src/session-ci-watcher.js +926 -0
- package/src/session-context.js +7 -2
- package/src/session-manager.js +3879 -308
- package/src/session-message-history.js +749 -37
- package/src/session-pr-status.js +654 -0
- package/src/session-pr-threads.js +271 -0
- package/src/session-preset-trust.js +3 -3
- package/src/session-preset.js +10 -5
- package/src/session-state-persistence.js +94 -17
- package/src/session-timeout-manager.js +20 -0
- package/src/session-title.js +168 -0
- package/src/session-token-store.js +70 -36
- package/src/session-wake.js +240 -0
- package/src/shell-approval-info.js +2 -2
- package/src/shell-approval-store.js +3 -1
- package/src/skills-loader.js +7 -4
- package/src/skills-manager.js +2 -2
- package/src/skills-trust.js +95 -13
- package/src/skills-usage.js +22 -5
- package/src/snapshots-store.js +2 -3
- package/src/statusline.js +596 -0
- package/src/subagent-counter.js +9 -1
- package/src/summarize-session.js +51 -4
- package/src/supervisor.js +99 -38
- package/src/sweep-stale-provider-dirs.js +95 -0
- package/src/thinking-level-wire.js +39 -0
- package/src/thinking-stream.js +179 -0
- package/src/token-manager.js +39 -9
- package/src/tool-result.js +61 -0
- package/src/transcript-sources.js +109 -0
- package/src/transcript-tasks.js +413 -31
- package/src/trusted-file-read.js +302 -0
- package/src/tunnel/base.js +0 -8
- package/src/tunnel/cloudflare.js +145 -35
- package/src/tunnel/index.js +13 -1
- package/src/tunnel/preview.js +64 -0
- package/src/tunnel-check.js +1 -1
- package/src/turn-outcome.js +137 -0
- package/src/turn-tracker.js +0 -0
- package/src/usage-normalize.js +122 -0
- package/src/user-shell-session.js +157 -37
- package/src/utils/agent-sdk-version.js +107 -0
- package/src/utils/argv-safety.js +741 -0
- package/src/utils/auth-cause.js +60 -0
- package/src/utils/binary-package-manifest.js +597 -0
- package/src/utils/binary-version.js +224 -0
- package/src/utils/bounded-regex-worker.js +25 -0
- package/src/utils/bounded-regex.js +153 -0
- package/src/utils/claude-binary.js +43 -0
- package/src/utils/claude-config-dir.js +245 -0
- package/src/utils/claude-login-command.js +16 -0
- package/src/utils/claude-native-route.js +81 -0
- package/src/utils/componentwise-resolver.js +301 -0
- package/src/utils/composite-key.js +45 -0
- package/src/utils/deploy-control-files.js +87 -0
- package/src/utils/exec-failure-reason.js +21 -0
- package/src/utils/git-repo.js +42 -0
- package/src/utils/is-entry-point.js +137 -0
- package/src/utils/iso-datetime.js +51 -0
- package/src/utils/node-pty-probe.js +95 -0
- package/src/utils/node-pty-support.js +118 -0
- package/src/utils/opened-file-path.js +167 -0
- package/src/utils/path-containment.js +165 -0
- package/src/utils/permission-mode-sidecar.js +51 -0
- package/src/utils/preflight.js +485 -29
- package/src/utils/read-limiter.js +217 -0
- package/src/utils/regular-file.js +375 -0
- package/src/utils/safe-regex.js +113 -0
- package/src/utils/small-file.js +129 -0
- package/src/utils/spawn-env.js +196 -5
- package/src/utils/stale-session-dirs.js +182 -0
- package/src/utils/stat-identity.js +43 -0
- package/src/utils/verify-binary.js +276 -0
- package/src/utils/verify-provenance.js +634 -0
- package/src/utils/wire-counters.js +48 -0
- package/src/web-task-manager.js +256 -16
- package/src/worktree-gc.js +11 -3
- package/src/ws-auth.js +69 -21
- package/src/ws-broadcaster.js +14 -2
- package/src/ws-client-manager.js +16 -1
- package/src/ws-client-sender.js +7 -0
- package/src/ws-file-ops/browser.js +370 -66
- package/src/ws-file-ops/common.js +384 -11
- package/src/ws-file-ops/git.js +615 -44
- package/src/ws-file-ops/index.js +7 -0
- package/src/ws-file-ops/memory.js +460 -0
- package/src/ws-file-ops/open-nofollow.js +354 -0
- package/src/ws-file-ops/reader.js +676 -94
- package/src/ws-forwarding.js +373 -55
- package/src/ws-handler-context.js +89 -2
- package/src/ws-history.js +1018 -177
- package/src/ws-message-handlers.js +23 -1
- package/src/ws-outbound-schemas.js +207 -0
- package/src/ws-permissions.js +589 -38
- package/src/ws-schemas.js +6 -0
- package/src/ws-server.js +936 -105
- package/src/dashboard-next/dist/assets/index-C2ipeGlq.js +0 -111
- package/src/dashboard-next/dist/assets/index-DM-_dISG.css +0 -1
- package/src/dashboard-next/dist/index.html +0 -13
package/src/byok-mcp-trust.js
CHANGED
|
@@ -1,11 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP server spawn trust store (#4457).
|
|
3
3
|
*
|
|
4
|
-
* Persists per-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Persists per-config trust decisions so a user is asked exactly ONCE per
|
|
5
|
+
* spawn-determining configuration — not on every chroxy restart.
|
|
6
|
+
*
|
|
7
|
+
* ## The key covers EVERYTHING that determines what executes (#7001)
|
|
8
|
+
*
|
|
9
|
+
* Up to v1 the key was the partial tuple `(name, command, args[0])` for stdio
|
|
10
|
+
* and `(name, sanitized-url)` for remote. That was unsound: `args[1..N]` and
|
|
11
|
+
* `env` are exactly as spawn-determining as `command`, so all three of
|
|
12
|
+
*
|
|
13
|
+
* { command: 'npx', args: ['-y', '@modelcontextprotocol/server-github'] }
|
|
14
|
+
* { command: 'npx', args: ['-y', '@attacker/pwn'] }
|
|
15
|
+
* { command: 'npx', args: ['-y', '…'], env: { NODE_OPTIONS: '--require /tmp/evil.js' } }
|
|
16
|
+
*
|
|
17
|
+
* collapsed onto the SAME key `["github","npx","-y"]`. Once any one of them was
|
|
18
|
+
* trusted, `isTrusted()` returned true for the other two, so a remove + re-add
|
|
19
|
+
* of the same name could swap in arbitrary host code with no trust prompt at all
|
|
20
|
+
* — and re-spawn it silently on every later session start. `_buildChildEnv()` is
|
|
21
|
+
* `{ ...process.env, ...config.env }`, so an injected `NODE_OPTIONS` alone was
|
|
22
|
+
* enough; it did not even need to change `command`.
|
|
23
|
+
*
|
|
24
|
+
* v2 therefore keys on a sha256 of a CANONICAL (key-sorted) JSON encoding of the
|
|
25
|
+
* full spawn-determining config — a digest rather than another hand-picked tuple,
|
|
26
|
+
* so a future spawn-determining field cannot be forgotten the way `env` was:
|
|
27
|
+
*
|
|
28
|
+
* - stdio: `{ v, kind: 'stdio', name, command, argsDigest, envDigest }`
|
|
29
|
+
* - remote: `{ v, kind: 'remote', name, url, urlDigest, headersDigest }`
|
|
30
|
+
*
|
|
31
|
+
* `args` / `env` / `headers` and the raw url enter the key as DIGESTS, never in
|
|
32
|
+
* cleartext, for one reason: the components are persisted (see below) and those
|
|
33
|
+
* fields routinely carry credentials (`--api-key=…`, `GITHUB_TOKEN`,
|
|
34
|
+
* `Authorization`, `?token=`). Digesting them keeps the key exhaustive while the
|
|
35
|
+
* store keeps its "no credential material ever reaches disk" property.
|
|
36
|
+
*
|
|
37
|
+
* Two deliberate consequences:
|
|
38
|
+
*
|
|
39
|
+
* 1. **Version bumps now re-prompt.** The pre-v2 rationale for excluding
|
|
40
|
+
* `args[1..N]` was that `mcp-github@1.4.2` → `@1.5.0` shouldn't re-ask. But
|
|
41
|
+
* "the package changed" is indistinguishable from "the package was swapped",
|
|
42
|
+
* and one prompt per genuine config edit is the correct price for closing an
|
|
43
|
+
* RCE path.
|
|
44
|
+
* 2. **A rotated credential inside a remote url re-prompts** — reversing the
|
|
45
|
+
* #6821 note that a changed query param would not. A query param can change
|
|
46
|
+
* what the endpoint does, and the SANITIZED url is published verbatim on the
|
|
47
|
+
* `mcp_servers` broadcast (`redactMcpUrl`), so a sanitized-url-only key was
|
|
48
|
+
* publicly known and freely inheritable by a different effective config.
|
|
49
|
+
*
|
|
50
|
+
* MIGRATION: v1 entries are DROPPED at load, not honoured (`loadTrustStore`
|
|
51
|
+
* requires `v === 2` and recomputes the key from the persisted components). There
|
|
52
|
+
* is deliberately NO compatibility shim — keeping the weak key alive for existing
|
|
53
|
+
* records would keep the collision exploitable. Previously-trusted servers
|
|
54
|
+
* re-prompt exactly once and are rewritten as v2 on the next allow. Re-prompting
|
|
55
|
+
* is the fail-safe direction; silently honouring a weak key is not.
|
|
9
56
|
*
|
|
10
57
|
* Storage: ~/.chroxy/mcp-trust.json (mode 0600). Atomic writes via temp +
|
|
11
58
|
* rename so a crashed `chroxy doctor` mid-prompt can't corrupt the file.
|
|
@@ -19,14 +66,30 @@
|
|
|
19
66
|
* time (UX) AND the load+write critical section is serialised across all
|
|
20
67
|
* gates in the same process.
|
|
21
68
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
69
|
+
* There is no "session-only" tier — once trusted, trusted forever for that
|
|
70
|
+
* exact config. Users who need to revoke can edit the JSON directly. A future
|
|
24
71
|
* iteration can add expiry timestamps without breaking the file format.
|
|
25
72
|
*/
|
|
26
73
|
|
|
74
|
+
import { createHash } from 'node:crypto'
|
|
27
75
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, renameSync, chmodSync, unlinkSync } from 'node:fs'
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
76
|
+
import { dirname } from 'node:path'
|
|
77
|
+
import { configPath } from './config-dir.js'
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* On-disk trust-record version. Bumped to 2 by #7001 (partial tuple → full
|
|
81
|
+
* spawn-config digest). `loadTrustStore` honours ONLY this version, so bumping it
|
|
82
|
+
* again is the supported way to force a re-prompt if the key composition ever
|
|
83
|
+
* has to change once more.
|
|
84
|
+
*/
|
|
85
|
+
export const TRUST_KEY_VERSION = 2
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sentinel for an absent/empty args list or string map. Deliberately not a valid
|
|
89
|
+
* sha256 hex string (64 hex chars), so "no env" can never be confused with the
|
|
90
|
+
* digest of some env, and the on-disk record stays readable.
|
|
91
|
+
*/
|
|
92
|
+
const EMPTY_DIGEST = 'none'
|
|
30
93
|
|
|
31
94
|
// Per-path tail of an in-process async mutex chain (#4460). Each
|
|
32
95
|
// withTrustStoreLock call awaits the current tail, then publishes a new
|
|
@@ -68,29 +131,172 @@ export async function withTrustStoreLock(filePath, critical) {
|
|
|
68
131
|
}
|
|
69
132
|
|
|
70
133
|
export function defaultTrustStorePath() {
|
|
71
|
-
return process.env.CHROXY_MCP_TRUST_PATH ||
|
|
134
|
+
return process.env.CHROXY_MCP_TRUST_PATH || configPath('mcp-trust.json')
|
|
72
135
|
}
|
|
73
136
|
|
|
74
137
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* stringified tuples are unambiguous by construction (quoted strings escape
|
|
86
|
-
* every embedded quote and control char), so no separator hack is needed.
|
|
138
|
+
* Return a credential-stripped, stable form of a remote MCP server url for
|
|
139
|
+
* use as a trust key (#6821). Strips userinfo (`user:pass@`), query, and
|
|
140
|
+
* fragment — none of those belong on disk, and stripping them means a
|
|
141
|
+
* rotated token or a changed query param does not re-prompt for the same
|
|
142
|
+
* endpoint. An unparseable url maps to a fixed placeholder — NEVER the raw
|
|
143
|
+
* input: recordTrust persists this value to disk, and a malformed url can
|
|
144
|
+
* still embed credential material (`user:pass@`, `?token=`). Collapsing all
|
|
145
|
+
* unparseable urls for a server name onto one key is fail-safe, because an
|
|
146
|
+
* unparseable url can never be connected to anyway (config parsing rejects
|
|
147
|
+
* it and fetch would throw).
|
|
87
148
|
*/
|
|
88
|
-
|
|
149
|
+
function sanitizeTrustUrl(url) {
|
|
150
|
+
if (typeof url !== 'string' || url.length === 0) return ''
|
|
151
|
+
try {
|
|
152
|
+
const u = new URL(url)
|
|
153
|
+
u.username = ''
|
|
154
|
+
u.password = ''
|
|
155
|
+
u.search = ''
|
|
156
|
+
u.hash = ''
|
|
157
|
+
return u.toString()
|
|
158
|
+
} catch {
|
|
159
|
+
return 'invalid-url'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function sha256Hex(input) {
|
|
164
|
+
return createHash('sha256').update(input, 'utf8').digest('hex')
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Deterministic JSON encoding: object keys sorted, array order preserved (arg
|
|
169
|
+
* ORDER is semantic — `['-e', 'code']` is not `['code', '-e']`).
|
|
170
|
+
*
|
|
171
|
+
* #4461's property is preserved for free: every string is JSON-quoted, so a
|
|
172
|
+
* component value containing a separator, quote, NUL or newline cannot be made to
|
|
173
|
+
* straddle a field boundary and collide with a different component split.
|
|
174
|
+
*/
|
|
175
|
+
function canonicalJson(value) {
|
|
176
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`
|
|
177
|
+
if (value !== null && typeof value === 'object') {
|
|
178
|
+
return `{${Object.keys(value)
|
|
179
|
+
.sort()
|
|
180
|
+
.map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`)
|
|
181
|
+
.join(',')}}`
|
|
182
|
+
}
|
|
183
|
+
return JSON.stringify(value === undefined ? null : value)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Digest of a spawn argv list. Order-sensitive, covers EVERY element (the v1 key
|
|
188
|
+
* covered only `args[0]`, which is what made `['-y', '@attacker/pwn']` collide
|
|
189
|
+
* with `['-y', '@modelcontextprotocol/server-github']`).
|
|
190
|
+
*/
|
|
191
|
+
export function argsDigest(args) {
|
|
192
|
+
const list = Array.isArray(args) ? args.map((a) => String(a)) : []
|
|
193
|
+
if (list.length === 0) return EMPTY_DIGEST
|
|
194
|
+
return sha256Hex(canonicalJson(list))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Digest of a string→string map (`env` or `headers`), canonically ordered so key
|
|
199
|
+
* insertion order cannot change the key. Values are hashed, never persisted —
|
|
200
|
+
* `env` and `headers` routinely carry API tokens.
|
|
201
|
+
*
|
|
202
|
+
* A `__proto__` key present as an OWN property (JSON.parse produces one) is
|
|
203
|
+
* covered like any other: `Object.entries` sees it, so it enters the digest and
|
|
204
|
+
* cannot be used to smuggle an uncovered difference past the key.
|
|
205
|
+
*/
|
|
206
|
+
export function stringMapDigest(map) {
|
|
207
|
+
if (!map || typeof map !== 'object' || Array.isArray(map)) return EMPTY_DIGEST
|
|
208
|
+
const entries = Object.entries(map)
|
|
209
|
+
.map(([k, v]) => [String(k), String(v)])
|
|
210
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
|
|
211
|
+
if (entries.length === 0) return EMPTY_DIGEST
|
|
212
|
+
return sha256Hex(canonicalJson(entries))
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The canonical component bag a trust key hashes over — and, verbatim, the record
|
|
217
|
+
* `recordTrust` persists. Keeping "what is hashed" and "what is stored" the SAME
|
|
218
|
+
* object is what lets `loadTrustStore` recompute the key from disk (the #4461
|
|
219
|
+
* tamper check) without ever storing a credential in cleartext.
|
|
220
|
+
*
|
|
221
|
+
* Two shapes (#6821), discriminated by an explicit `kind` so they can never
|
|
222
|
+
* alias:
|
|
223
|
+
* - remote: `{ v, kind: 'remote', name, url, urlDigest, headersDigest }` —
|
|
224
|
+
* `url` is the credential-stripped display form; `urlDigest` covers the FULL
|
|
225
|
+
* raw url (userinfo, query, fragment) so a changed query param is a different
|
|
226
|
+
* endpoint configuration.
|
|
227
|
+
* - stdio: `{ v, kind: 'stdio', name, command, argsDigest, envDigest }` —
|
|
228
|
+
* `command` stays cleartext (it is the field the consent prompt shows, and a
|
|
229
|
+
* binary path is not credential material); the full argv and env are covered
|
|
230
|
+
* by digests.
|
|
231
|
+
*/
|
|
232
|
+
export function trustKeyComponents(server) {
|
|
89
233
|
if (!server || typeof server !== 'object') throw new Error('trustTupleKey: missing server')
|
|
90
234
|
const name = String(server.name || '')
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
235
|
+
const rawUrl = typeof server.url === 'string' ? server.url : ''
|
|
236
|
+
if (rawUrl) {
|
|
237
|
+
return {
|
|
238
|
+
v: TRUST_KEY_VERSION,
|
|
239
|
+
kind: 'remote',
|
|
240
|
+
name,
|
|
241
|
+
url: sanitizeTrustUrl(rawUrl),
|
|
242
|
+
urlDigest: sha256Hex(rawUrl),
|
|
243
|
+
headersDigest: stringMapDigest(server.headers),
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
v: TRUST_KEY_VERSION,
|
|
248
|
+
kind: 'stdio',
|
|
249
|
+
name,
|
|
250
|
+
command: String(server.command || ''),
|
|
251
|
+
argsDigest: argsDigest(server.args),
|
|
252
|
+
envDigest: stringMapDigest(server.env),
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The trust key for a server config: sha256 over the canonical component bag.
|
|
258
|
+
*
|
|
259
|
+
* Named `trustTupleKey` for continuity with #4457/#4461 call sites, but since
|
|
260
|
+
* #7001 it is a DIGEST of the whole spawn-determining config, not a tuple of
|
|
261
|
+
* hand-picked fields. Two configs share a key iff they would spawn/connect
|
|
262
|
+
* identically.
|
|
263
|
+
*/
|
|
264
|
+
export function trustTupleKey(server) {
|
|
265
|
+
return sha256Hex(canonicalJson(trustKeyComponents(server)))
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Rebuild the component bag from a persisted record, reading EXACTLY the fields
|
|
270
|
+
* the bag defines (never a spread of the raw entry — an attacker-added extra key
|
|
271
|
+
* must not be able to participate in the recompute). Returns null for anything
|
|
272
|
+
* that is not a current-version record, which includes every v1 entry: those
|
|
273
|
+
* carry `args0` and no `v`, so they are dropped rather than honoured.
|
|
274
|
+
*/
|
|
275
|
+
function componentsFromEntry(entry) {
|
|
276
|
+
if (!entry || typeof entry !== 'object') return null
|
|
277
|
+
if (entry.v !== TRUST_KEY_VERSION) return null
|
|
278
|
+
const str = (v) => (typeof v === 'string' ? v : '')
|
|
279
|
+
if (entry.kind === 'remote') {
|
|
280
|
+
return {
|
|
281
|
+
v: TRUST_KEY_VERSION,
|
|
282
|
+
kind: 'remote',
|
|
283
|
+
name: str(entry.name),
|
|
284
|
+
url: str(entry.url),
|
|
285
|
+
urlDigest: str(entry.urlDigest),
|
|
286
|
+
headersDigest: str(entry.headersDigest),
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (entry.kind === 'stdio') {
|
|
290
|
+
return {
|
|
291
|
+
v: TRUST_KEY_VERSION,
|
|
292
|
+
kind: 'stdio',
|
|
293
|
+
name: str(entry.name),
|
|
294
|
+
command: str(entry.command),
|
|
295
|
+
argsDigest: str(entry.argsDigest),
|
|
296
|
+
envDigest: str(entry.envDigest),
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return null
|
|
94
300
|
}
|
|
95
301
|
|
|
96
302
|
/**
|
|
@@ -104,20 +310,26 @@ export function loadTrustStore(filePath = defaultTrustStorePath(), { log } = {})
|
|
|
104
310
|
const arr = Array.isArray(raw?.trustedTuples) ? raw.trustedTuples : []
|
|
105
311
|
const tuples = new Set()
|
|
106
312
|
const entries = []
|
|
313
|
+
let legacyDropped = 0
|
|
107
314
|
for (const t of arr) {
|
|
108
315
|
if (!t || typeof t.key !== 'string') continue
|
|
316
|
+
// #7001: a pre-v2 record was computed with the weak (name, command,
|
|
317
|
+
// args[0]) / (name, sanitized-url) key, which collided across configs that
|
|
318
|
+
// spawn different code. It is DROPPED, never translated — honouring it
|
|
319
|
+
// would keep that collision exploitable. The user re-prompts once and the
|
|
320
|
+
// record is rewritten as v2 on the next allow.
|
|
321
|
+
const components = componentsFromEntry(t)
|
|
322
|
+
if (!components) {
|
|
323
|
+
legacyDropped += 1
|
|
324
|
+
continue
|
|
325
|
+
}
|
|
109
326
|
// #4461: recompute the canonical key from the recorded components and
|
|
110
327
|
// drop any entry whose stored `key` doesn't match. A tampered entry
|
|
111
328
|
// (e.g. stored key kept but command swapped to something dangerous)
|
|
112
329
|
// yields a mismatch and is silently dropped — the user re-prompts
|
|
113
|
-
// for that
|
|
330
|
+
// for that config on next start. Pre-tamper trust is forfeit; correct
|
|
114
331
|
// behaviour given the integrity claim is broken.
|
|
115
|
-
const
|
|
116
|
-
const recomputed = trustTupleKey({
|
|
117
|
-
name: typeof t.name === 'string' ? t.name : '',
|
|
118
|
-
command: typeof t.command === 'string' ? t.command : '',
|
|
119
|
-
args: [args0],
|
|
120
|
-
})
|
|
332
|
+
const recomputed = sha256Hex(canonicalJson(components))
|
|
121
333
|
if (recomputed !== t.key) {
|
|
122
334
|
log?.warn?.(`MCP trust store ${filePath} entry "${t.name}" key tampered (recomputed mismatch); dropping`)
|
|
123
335
|
continue
|
|
@@ -125,6 +337,13 @@ export function loadTrustStore(filePath = defaultTrustStorePath(), { log } = {})
|
|
|
125
337
|
tuples.add(t.key)
|
|
126
338
|
entries.push(t)
|
|
127
339
|
}
|
|
340
|
+
if (legacyDropped > 0) {
|
|
341
|
+
log?.warn?.(
|
|
342
|
+
`MCP trust store ${filePath}: dropped ${legacyDropped} pre-v${TRUST_KEY_VERSION} trust record(s) ` +
|
|
343
|
+
'— they were keyed on a partial config (command + args[0] only) and are no longer honoured (#7001); ' +
|
|
344
|
+
'affected MCP servers will ask for trust once more',
|
|
345
|
+
)
|
|
346
|
+
}
|
|
128
347
|
return { tuples, path: filePath, entries }
|
|
129
348
|
} catch (err) {
|
|
130
349
|
log?.warn?.(`MCP trust store ${filePath} unreadable: ${err?.message || err}`)
|
|
@@ -142,13 +361,11 @@ export function recordTrust(server, filePath = defaultTrustStorePath()) {
|
|
|
142
361
|
const existing = loadTrustStore(filePath)
|
|
143
362
|
if (existing.tuples.has(key)) return existing
|
|
144
363
|
const entries = Array.isArray(existing.entries) ? [...existing.entries] : []
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
trustedAt: new Date().toISOString(),
|
|
151
|
-
})
|
|
364
|
+
// #7001: persist the component bag the key was hashed over, verbatim, so
|
|
365
|
+
// loadTrustStore can recompute and verify it. Only digests of args/env/headers
|
|
366
|
+
// and of the raw url are written — no argv element, env value, header value or
|
|
367
|
+
// url credential ever reaches disk.
|
|
368
|
+
entries.push({ ...trustKeyComponents(server), key, trustedAt: new Date().toISOString() })
|
|
152
369
|
const dir = dirname(filePath)
|
|
153
370
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 0o700 })
|
|
154
371
|
const tmp = `${filePath}.tmp`
|