d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
32 lines
1.7 KiB
TypeScript
32 lines
1.7 KiB
TypeScript
import type { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js'
|
|
import { createPinnedFetch } from '@/lib/core/security/input-validation.server'
|
|
import { validateMcpServerSsrf } from '@/lib/mcp/domain-check'
|
|
|
|
/**
|
|
* Builds a `FetchLike` that validates every outbound request URL against the
|
|
* MCP SSRF policy before issuing it, then pins the connection to the resolved
|
|
* IP. Unlike the live transport — where the server URL is validated once up
|
|
* front — OAuth discovery and RFC 7009 revocation follow URLs taken verbatim
|
|
* from attacker-controllable authorization-server metadata
|
|
* (`authorization_servers`, `token_endpoint`, `revocation_endpoint`, …). Each
|
|
* such hop must be re-validated, so this guard runs `validateMcpServerSsrf`
|
|
* per request and rejects private/reserved/loopback targets (honoring
|
|
* `ALLOWED_MCP_DOMAINS` and self-hosted localhost rules).
|
|
*
|
|
* Note: a caller-provided `AbortSignal` in `init` only bounds the HTTP request,
|
|
* not the validation DNS lookup — Node's `dns.lookup` does not accept a signal,
|
|
* so a hanging resolution can extend the overall call past the caller's timeout
|
|
* by up to the OS DNS timeout. Acceptable here because all consumers are
|
|
* best-effort, non-blocking flows (OAuth discovery and RFC 7009 revocation).
|
|
*
|
|
* @throws McpSsrfError if a request URL resolves to a blocked IP address
|
|
*/
|
|
export function createSsrfGuardedMcpFetch(): FetchLike {
|
|
return (async (url, init) => {
|
|
const target = typeof url === 'string' ? url : url.href
|
|
const resolvedIP = await validateMcpServerSsrf(target)
|
|
const pinnedFetch: FetchLike = resolvedIP ? createPinnedFetch(resolvedIP) : globalThis.fetch
|
|
return pinnedFetch(url, init)
|
|
}) satisfies FetchLike
|
|
}
|