mcp-trellis 2.2.0 → 3.0.0

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.
Files changed (94) hide show
  1. package/dist/adapters/node-request.d.ts +5 -0
  2. package/dist/adapters/node-request.d.ts.map +1 -1
  3. package/dist/adapters/node-request.js +17 -1
  4. package/dist/adapters/node-request.js.map +1 -1
  5. package/dist/adapters/node.d.ts +15 -0
  6. package/dist/adapters/node.d.ts.map +1 -1
  7. package/dist/adapters/node.js +38 -0
  8. package/dist/adapters/node.js.map +1 -1
  9. package/dist/audit.d.ts.map +1 -1
  10. package/dist/audit.js +63 -6
  11. package/dist/audit.js.map +1 -1
  12. package/dist/clients.js +2 -2
  13. package/dist/clients.js.map +1 -1
  14. package/dist/http/origins.d.ts.map +1 -1
  15. package/dist/http/origins.js +13 -2
  16. package/dist/http/origins.js.map +1 -1
  17. package/dist/mcp/dispatch.d.ts.map +1 -1
  18. package/dist/mcp/dispatch.js +2 -1
  19. package/dist/mcp/dispatch.js.map +1 -1
  20. package/dist/mcp/methods.d.ts +1 -0
  21. package/dist/mcp/methods.d.ts.map +1 -1
  22. package/dist/mcp/methods.js +1 -0
  23. package/dist/mcp/methods.js.map +1 -1
  24. package/dist/mcp/registry.d.ts.map +1 -1
  25. package/dist/mcp/registry.js +15 -3
  26. package/dist/mcp/registry.js.map +1 -1
  27. package/dist/mcp/rpc-handlers.d.ts.map +1 -1
  28. package/dist/mcp/rpc-handlers.js +58 -11
  29. package/dist/mcp/rpc-handlers.js.map +1 -1
  30. package/dist/mcp/tools.d.ts +14 -0
  31. package/dist/mcp/tools.d.ts.map +1 -1
  32. package/dist/mcp/tools.js +114 -17
  33. package/dist/mcp/tools.js.map +1 -1
  34. package/dist/mcp/validate.d.ts +7 -1
  35. package/dist/mcp/validate.d.ts.map +1 -1
  36. package/dist/mcp/validate.js +58 -24
  37. package/dist/mcp/validate.js.map +1 -1
  38. package/dist/oauth/audit.d.ts +10 -0
  39. package/dist/oauth/audit.d.ts.map +1 -1
  40. package/dist/oauth/audit.js +25 -1
  41. package/dist/oauth/audit.js.map +1 -1
  42. package/dist/oauth/cimd/cimd-parse.d.ts.map +1 -1
  43. package/dist/oauth/cimd/cimd-parse.js +27 -14
  44. package/dist/oauth/cimd/cimd-parse.js.map +1 -1
  45. package/dist/oauth/cimd/cimd-ssrf.d.ts.map +1 -1
  46. package/dist/oauth/cimd/cimd-ssrf.js +39 -6
  47. package/dist/oauth/cimd/cimd-ssrf.js.map +1 -1
  48. package/dist/oauth/cimd/cimd.d.ts +11 -2
  49. package/dist/oauth/cimd/cimd.d.ts.map +1 -1
  50. package/dist/oauth/cimd/cimd.js +40 -34
  51. package/dist/oauth/cimd/cimd.js.map +1 -1
  52. package/dist/oauth/cimd/failure.d.ts +19 -0
  53. package/dist/oauth/cimd/failure.d.ts.map +1 -0
  54. package/dist/oauth/cimd/failure.js +28 -0
  55. package/dist/oauth/cimd/failure.js.map +1 -0
  56. package/dist/oauth/crypto/clientauth.d.ts.map +1 -1
  57. package/dist/oauth/crypto/clientauth.js +7 -6
  58. package/dist/oauth/crypto/clientauth.js.map +1 -1
  59. package/dist/oauth/endpoints/authorize.d.ts.map +1 -1
  60. package/dist/oauth/endpoints/authorize.js +24 -6
  61. package/dist/oauth/endpoints/authorize.js.map +1 -1
  62. package/dist/oauth/endpoints/consent-page.d.ts.map +1 -1
  63. package/dist/oauth/endpoints/consent-page.js +34 -1
  64. package/dist/oauth/endpoints/consent-page.js.map +1 -1
  65. package/dist/oauth/endpoints/token.d.ts.map +1 -1
  66. package/dist/oauth/endpoints/token.js +7 -1
  67. package/dist/oauth/endpoints/token.js.map +1 -1
  68. package/dist/oauth/policy/redirect.d.ts +6 -0
  69. package/dist/oauth/policy/redirect.d.ts.map +1 -1
  70. package/dist/oauth/policy/redirect.js +6 -0
  71. package/dist/oauth/policy/redirect.js.map +1 -1
  72. package/dist/oauth/policy/reqbody.d.ts +6 -1
  73. package/dist/oauth/policy/reqbody.d.ts.map +1 -1
  74. package/dist/oauth/policy/reqbody.js +8 -3
  75. package/dist/oauth/policy/reqbody.js.map +1 -1
  76. package/dist/oauth/types.d.ts +3 -1
  77. package/dist/oauth/types.d.ts.map +1 -1
  78. package/dist/util/clip.d.ts +7 -0
  79. package/dist/util/clip.d.ts.map +1 -0
  80. package/dist/util/clip.js +13 -0
  81. package/dist/util/clip.js.map +1 -0
  82. package/dist/util/json.d.ts +5 -0
  83. package/dist/util/json.d.ts.map +1 -1
  84. package/dist/util/json.js +21 -0
  85. package/dist/util/json.js.map +1 -1
  86. package/dist/util/own.d.ts +8 -0
  87. package/dist/util/own.d.ts.map +1 -0
  88. package/dist/util/own.js +8 -0
  89. package/dist/util/own.js.map +1 -0
  90. package/docs/guide.md +15 -4
  91. package/docs/reference.md +2 -1
  92. package/docs/security.md +5 -3
  93. package/docs/troubleshooting.md +1 -0
  94. package/package.json +2 -2
package/docs/security.md CHANGED
@@ -21,13 +21,13 @@ This is a **library** threat model, not a third-party audit badge.
21
21
 
22
22
  | Risk | Mitigation |
23
23
  |------|------------|
24
- | Attacker-driven cross-site authorization (a logged-in user visits an attacker page and is silently walked through `/authorize`, catching the code on an attacker-controlled `redirect_uri`) | **`/authorize` never issues a code directly.** A resolved session renders a consent interstitial (built in, hardened — CSP, `X-Frame-Options: DENY`, `Referrer-Policy: no-referrer`, escaped reflection — or your own via `consent.render`) and only issues a code after an explicit `POST ${oauthPath}/consent` approval. The approval ticket is sealed (AES-GCM, HKDF-derived per-type key, type bound in as AEAD data — see `sealed.ts`), single-use, 5-minute TTL, and re-checked against the resolved user at redemption; it can never be redeemed as an auth code or vice versa. PKCE alone does **not** defend against this — it proves possession of the verifier, not identity of a legitimate client — so this is a distinct control, not a restatement of PKCE. `preApprovedClientIds` skips the screen only for ids `clientStore` actually resolves; a DCR or self-invented id is never trusted to skip it. The built-in interstitial's CSP scopes `form-action` to `'self'` plus the validated `redirect_uri`'s own origin — Chromium enforces `form-action` across the redirect the approval POST produces, not just its immediate target, so a custom `consent.render` that sets its own CSP must do the same or the callback to the client's own origin gets silently blocked. |
24
+ | Attacker-driven cross-site authorization (a logged-in user visits an attacker page and is silently walked through `/authorize`, catching the code on an attacker-controlled `redirect_uri`) | **`/authorize` never issues a code directly.** A resolved session renders a consent interstitial (built in, hardened — CSP, `X-Frame-Options: DENY`, `Referrer-Policy: no-referrer`, escaped reflection — or your own via `consent.render`) and only issues a code after an explicit `POST ${oauthPath}/consent` approval. The approval ticket is sealed (AES-GCM, HKDF-derived per-type key, type bound in as AEAD data — see `sealed.ts`), single-use, 5-minute TTL, and re-checked against the resolved user at redemption; it can never be redeemed as an auth code or vice versa. PKCE alone does **not** defend against this — it proves possession of the verifier, not identity of a legitimate client — so this is a distinct control, not a restatement of PKCE. `preApprovedClientIds` skips the screen only for ids `clientStore` actually resolves; a DCR or self-invented id is never trusted to skip it. The built-in interstitial's CSP scopes `form-action` to `'self'` plus the validated `redirect_uri`'s own origin (its scheme, e.g. `myapp:`, for a custom-scheme URI whose origin is opaque) — Chromium enforces `form-action` across the redirect the approval POST produces, not just its immediate target, so a custom `consent.render` that sets its own CSP must do the same or the callback to the client's own origin gets silently blocked. |
25
25
  | Confused deputy (token usable at the wrong MCP) | RFC 8707: `resource` required on authorize + token; bound into the auth code; must equal this AS's canonical resource (`canonicalResource(origin, resourcePath)`). Passed into `mintAccessToken` / `refreshAccessToken` so you can embed `aud`. |
26
26
  | Refresh token replayed at another resource on the same AS | Library cannot inspect opaque refresh tokens — **`refreshAccessToken` MUST reject tokens not originally issued for the given `resource`** |
27
27
  | Audience not enforced at the RS | **`createMcpApp` enforces this** — `verifyToken` returns the token's `audience` and the library rejects any mismatch against `canonicalResource(origin, resourcePath)`. With bare `createMcpHandler`, the check is yours. |
28
28
  | Open redirect after login | Your login page must validate `next` is same-origin before redirecting |
29
29
  | Auth-code replay across instances | Pass a shared `codeStore`; in-memory `jti` (the auth code's single-use id) map is process-local only |
30
- | Origin spoofing on Node | Pass explicit `origin`, or `trustProxy: true` only behind a proxy that strips client `X-Forwarded-*`. Host-derived origin **requires** non-empty `allowedOrigins` on `asNodeHandler` (`["*"]` to opt out loudly) |
30
+ | Origin spoofing on Node | Pass explicit `origin`, or `trustProxy: true` only behind a proxy that strips client `X-Forwarded-*`. Host-derived origin **requires** non-empty `allowedOrigins` on `asNodeHandler` (`["*"]` to opt out loudly). A fixed `origin` ignores the `Host` header, so a DNS-rebinding page could otherwise drive the whole OAuth flow from a victim's browser: for a loopback `origin` `asNodeHandler` rejects any other `Host` by default, and `allowedHosts` does the same for any origin |
31
31
  | A Host/`X-Forwarded-*` header carrying a path, query, fragment, or embedded credentials (`evil.test/../trusted.test`, `user:pass@evil.test`) building an origin string that merely looks well-formed | `resolveOrigin` always normalizes and validates through `URL`, rejecting any of those (plus a non-`http(s)` `X-Forwarded-Proto`) with `InvalidOriginError` — `asNodeHandler` answers it **400**, not the generic 500 an actual unexpected failure gets |
32
32
  | Browser `Origin` on MCP (DNS rebinding / CSRF) | `allowedRequestOrigins` on `createMcpHandler` / `createMcpApp`. No `Origin` header → allowed (native clients). Omitted allowlist → **reject** any present `Origin`. `"*"` opts out. Distinct from Node Host `allowedOrigins` |
33
33
  | Scope escalation at authorize | Requested `scope` is validated against the advertised `scopes` and rejected with `invalid_scope`; the grant is bound into the auth code and handed to `mintAccessToken` |
@@ -38,9 +38,11 @@ This is a **library** threat model, not a third-party audit badge.
38
38
  | An unauthenticated caller enumerating which `client_id`s a locked-down server knows, via distinguishable `/token`/`/revoke` error text or response timing | Every client-auth failure at `/token` and `/revoke` collapses to one `invalid_client` / "client authentication failed" — previously up to five distinguishable messages named exactly why (wrong method, missing secret, misconfigured store, unknown id). Every rejection path in `firstClientAuthError` for a client_id that *is* known — wrong auth method, no secret presented, wrong secret, no `secretHash`/`verifySecret` on file — runs the same fixed-cost dummy or real comparison before returning, so response timing alone can't tell "known client, wrong method" apart from "known client, wrong secret." An unknown `client_id` on a locked-down server (`allowUnregisteredClients: false`) pays the identical fixed cost, so the crypto-verification cost itself can't distinguish "unknown" from "known, wrong secret" either. `/authorize`'s `unauthorized_client` is unchanged and stays descriptive — a human debugging a browser flow, not a bare API response, and a locked-down server already announces the same fact by omitting `registration_endpoint` |
39
39
  | Auth codes readable by anyone who sees one — browser history, `Referer`, proxy logs | Auth codes are sealed (AES-GCM, `sealed.ts`), not signed-only. Legacy v1 (HMAC-signed, not encrypted) codes are **rejected** since 1.0 — complete any rolling deploy before upgrading past 0.4.x |
40
40
  | An upstream API's error body leaking into the model or the audit log via `apiTool` | Default is status-only — the upstream response body is never forwarded on a non-2xx result, since it's a return value `onToolError` redaction never sees. Use `onError` for (a redacted version of) the body |
41
+ | `apiTool` as a credential-forwarding / SSRF primitive via upstream redirects | Redirects are not followed by default (`redirect: "manual"`): `fetch` would forward custom auth headers (`X-Api-Key`) and a 307 body to the `Location` and could fetch an internal address, returning it to the model. `"follow"` is an explicit opt-in for a fully trusted upstream |
42
+ | A tool call that amplifies a small request into a huge validation error | Validation stops after 20 violations and the message is capped at 2000 characters; audit copies of tool errors are capped at 1000 |
41
43
  | `/authorize` errors delivered as a bare JSON body a connector can't act on | RFC 6749 §4.1.2.1: once `redirect_uri` is validated, every remaining error (`unsupported_response_type`, PKCE, `invalid_scope`, `invalid_target`, …) redirects to the client's own callback with `?error=…&state=…` instead. `redirect_uri` validity itself, and an oversized `state`, stay direct JSON — the URI is what's in question in the first case, and reflecting an oversized `state` into its own error redirect would recreate the DoS the length cap exists to prevent |
42
44
  | DCR-issued `client_id` reused with a substituted `redirect_uri` | `/register` no longer returns a bare random id — the `client_id` **is** a sealed, self-verifying assertion of the exact `redirect_uris` it registered (`sealed.ts`, type `"client"`), with zero server-side storage. `/authorize` unseals it and binds the request to that list, the same protection a stored registration would give. This does not require the *identity* of the client to be verified — an attacker can still call `/register` and mint their own sealed id — so it stops URI substitution on a legitimate connector's id, not impersonation; the consent step above is what stops impersonation. `requireRegisteredClients` defaults to **true** since 1.0 (reject any `client_id` that isn't `clientStore`-resolved or self-sealed); set `false` only to accept invented public ids. Enforced at `/authorize`, and — since 1.2.0 — at `/token`'s `refresh_token` grant and at `/revoke` too, closing a gap where an invented `client_id` that never went through `/authorize` could still authenticate on either (the `authorization_code` grant was never actually exposed by this: a redeemable code's `client_id` is bound into its sealed payload at `/authorize` time, where the check already ran). Opt into CIMD with `cimd: true` for URL-shaped client_ids (off by default) |
43
- | CIMD fetch as SSRF proxy (attacker supplies `https://…` `client_id`) | **Off by default** (`cimd: true` to enable). When on: HTTPS-only fetch, private/loopback/link-local/NAT64/`::ffff:` blocked (incl. bracketed IPv6 **and full-form mapped encodings DNS may return**, e.g. `0:0:0:0:0:ffff:7f00:1`), DNS lookup required before fetch and re-checked after the body, unparseable IPv6 lookup results fail closed, 5 KB stream-capped body / 10 s per hop covering the body read / 3 same-origin redirects (cross-origin redirects rejected), public clients only, `http:` redirect_uris loopback-only (`127.0.0.1` / `[::1]`, never `localhost`). Also blocked: `192.0.0/24`, `198.18/15`, multicast/reserved `224/4`–`240/4`, IPv6 multicast `ff00::/8`, 6to4 `2002::/16`, IPv4-compatible `::a.b.c.d` (and full-form private embeds). `/token` and `/revoke` **re-resolve** CIMD — never accept URL-shaped ids by shape alone; pass `cimdCache` (strongly recommended) or every refresh/revoke re-fetches the document, and a failed re-resolve is audited as `cimd_resolve_failed`. **Ceiling:** TCP connect is not pinned to the looked-up addresses (zero-dep Web `fetch`); classic DNS rebinding between lookup and connect remains possible until a custom dispatcher pins the IP — do not treat CIMD as production-complete SSRF defense until then |
45
+ | CIMD fetch as SSRF proxy (attacker supplies `https://…` `client_id`) | **Off by default** (`cimd: true` to enable). When on: HTTPS-only fetch, private/loopback/link-local/NAT64/`::ffff:` blocked (incl. bracketed IPv6 **and full-form mapped encodings DNS may return**, e.g. `0:0:0:0:0:ffff:7f00:1`), DNS lookup required before fetch and re-checked after the body, unparseable IPv6 lookup results fail closed, 5 KB stream-capped body / 10 s per hop covering the body read / 3 same-origin redirects (cross-origin redirects rejected), public clients only, `http:` redirect_uris loopback-only (`127.0.0.1` / `[::1]`, never `localhost`). Also blocked: `192.0.0/24`, `198.18/15`, multicast/reserved `224/4`–`240/4`, IPv6 multicast `ff00::/8`, 6to4 `2002::/16`, IPv4-compatible `::a.b.c.d` (and full-form private embeds). `/token` and `/revoke` **re-resolve** CIMD — never accept URL-shaped ids by shape alone; pass `cimdCache` (strongly recommended) or every refresh/revoke re-fetches the document, and a failed resolve is audited as `cimd_resolve_failed` at `/authorize`, `/token` and `/revoke` with a reason code (`http_status: status 403 (authorize)`; never an address, header, body or redirect target) while the connector gets one generic `unauthorized_client`. **Ceiling:** TCP connect is not pinned to the looked-up addresses (zero-dep Web `fetch`); classic DNS rebinding between lookup and connect remains possible until a custom dispatcher pins the IP — do not treat CIMD as production-complete SSRF defense until then |
44
46
  | Naming only confidential clients doesn't actually block public ones | `clients: ["gemini"]` (or `allowUnregisteredClients: false`) is **enforced**: DCR unmounted, dropped from AS metadata, unresolved `client_id` rejected with `unauthorized_client` at `authorize` and `invalid_client` at `token` and `revoke` |
45
47
  | DCR / token-endpoint abuse | Edge or reverse-proxy rate limiting on `/register` and `/token`, **plus** a library-enforced request body cap (see "Also designed in") — the library does not rate-limit by request count, but an unbounded body was previously a memory-exhaustion vector on its own regardless of rate |
46
48
  | A weak or copy-pasted `codeSecret` (it can forge an auth code — or, since 0.3.0, a consent ticket or DCR client assertion — for any userId/scope/resource) | Validated at the point of use: a string or array form throws at `createOAuthRouter` construction (every array entry checked, and the array itself must be non-empty), a function form on every call. Minimum 32 characters per entry, and the exact literals this package's own docs and examples have published are denylisted by name, as is any secret containing the examples' `do-not-reuse` marker — copy-paste is the realistic failure mode. The examples themselves read `MCP_SECRET` (or `OAUTH_CODE_SECRET` for the advanced multi-secret recipes) from the environment and ship no usable default, and a test fails if any `codeSecret` literal in `examples/`, `README.md` or `docs/` is one the library would accept. This only catches the obvious cases; a leaked or brute-forceable 32+ character secret is still a full bypass, same as before |
@@ -14,6 +14,7 @@
14
14
  | Wrong user's data | Data query ignores authenticated identity | Filter by verified principal and tenant; never trust a tool argument for ownership. |
15
15
  | Switching login does not switch connector user | Connector retains its previously issued token | Disconnect and reauthorize with the intended account. |
16
16
  | Initialization works but tools fail | Initialize is public | Test authenticated `tools/call`; initialize alone proves no auth flow. |
17
+ | `unauthorized_client: CIMD client_id could not be resolved` | The connector is told one generic error on purpose; the cause is in your audit sink | Read the `cimd_resolve_failed` entry: `reason` is `<code>[: detail] (authorize\|token/revoke)`. `http_status: status 403` = the document host refused the fetch; `auth_method_unsupported` = its document excludes `none`; `dns_failed (ENOTFOUND)` / `dns_unavailable` = no DNS from this runtime, pass `cimdLookup`; `blocked_address` = it resolves to a non-public address. Pass `cimdCache` so refresh does not re-fetch. |
17
18
  | Client requests an unsupported protocol | Package supports the revisions in `src/mcp/protocol.ts` | Record negotiation; do not claim a live pass from a successful HTTP status alone. |
18
19
 
19
20
  See [security responsibilities](security.md) before replacing production token verification with example code. Share sanitized errors in an issue, never access tokens or session cookies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-trellis",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Add authenticated remote MCP connectors to existing TypeScript SaaS apps using your existing users and auth.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -81,7 +81,7 @@
81
81
  "node": ">=20"
82
82
  },
83
83
  "devDependencies": {
84
- "@biomejs/biome": "2.5.11",
84
+ "@biomejs/biome": "2.5.14",
85
85
  "@types/node": "^26.4.1",
86
86
  "tsx": "^4.19.3",
87
87
  "typescript": "^5.8.2"