@apify/actors-mcp-server (apify/apify-mcp-server) improper input validation
Description
The MCP HTTP entry point keeps its per-session state in plain object literals (const mcpServers: { [sessionId: string]: ActorsMcpServer } = {}; and const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};, src/dev_server.ts:234-235) and indexes them directly with the client-controlled Mcp-Session-Id header (src/dev_server.ts:287-289 for POST /, src/dev_server.ts:394 for GET /, src/dev_server.ts:415 for DELETE /). Because there is no own-property check, values that name inherited Object.prototype members resolve to real objects/functions: transports['constructor'] returns the built-in Object constructor, which is truthy, so the !transport -> 404 Session not found decision is bypassed and a function object is assigned to transport. The subsequent transport.handleRequest(...) call (src/dev_server.ts:350, :406, :423) throws TypeError: transport.handleRequest is not a function, which respondWithError() turns into HTTP 500 / -32603 plus an exception-level stack trace in the server log.
All three routes (POST, GET, DELETE) were reproduced dynamically against the shipped code (npm @apify/actors-mcp-server@0.15.6-beta.1, byte-identical to the audited repository master ee87bb7) using no credentials at all: Mcp-Session-Id: constructor returns HTTP 500 on POST /, Mcp-Session-Id: toString returns HTTP 500 on DELETE /, and Mcp-Session-Id: valueOf returns HTTP 500 on GET /. Control requests (no header, or a random UUID) return 400/-32000 and 404 respectively, proving the 500s are caused solely by the prototype-chain hit. The demonstrated effects are an unauthenticated remote uncaught exception (HTTP 500), a bypass of the session-existence check (the request is processed as if a session existed), and remote-reproducible exception-level log flooding. No other session's data is exposed and the process does not terminate, so confidentiality and service availability are not shown to be affected; the CVSS base score is therefore reported as 6.4 (medium).
Details
Root cause. The session registry of the HTTP entry point is a plain object literal, and lookups use the raw request header as a property name:
src/dev_server.ts:234-235-createExpressApp()declaresconst mcpServers: { [sessionId: string]: ActorsMcpServer } = {};andconst transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};. Neither object is created withObject.create(null), neither is aMap, and no lookup is guarded byObject.hasOwn/Object.prototype.hasOwnProperty.call.src/dev_server.ts:283-289(app.post('/', ...)) -const sessionId = req.headers['mcp-session-id'] as string | undefined;followed byif (sessionId && transports[sessionId]) { transport = transports[sessionId]; }. ForsessionId = 'constructor'the property lookup walks the prototype chain and returnsObject.prototype.constructor, i.e. the built-inObjectconstructor function. That value is truthy, so the conditional succeeds and the function object is assigned totransport, which is typed asStreamableHTTPServerTransportbut is not one.src/dev_server.ts:394(app.get('/', ...), the SSE stream route) -const transport = transports[sessionId || ''] as StreamableHTTPServerTransport | undefined;followed byif (!transport) { ... 404 Session not found ... }. The truthy inherited function again defeats the 404 branch.src/dev_server.ts:415(app.delete('/', ...)) - the sametransports[sessionId || '']lookup withif (transport) { ... }.
Trust-boundary failure. The three routes are reachable without any credential: authentication in this server is only enforced inside the initialize branch of POST / (resolveRequestAuth(), src/dev_server.ts:109-122, called at src/dev_server.ts:307), whereas the session-table lookups happen before (POST, line 283-289), or entirely outside, any auth check (GET line 392, DELETE line 412). The trust boundary is therefore "the session table must only contain server-generated UUID session ids", and that boundary is enforced by nothing: any header value is accepted as a key, and Object.prototype supplies a truthy value for a set of magic names. Consequently an unauthicated request is treated as if it referenced a live session: in the POST branch the code then also executes req.body.params = injectMcpSessionId(req.body.params, sessionId) (src/dev_server.ts:377-379), injecting the attacker-supplied string as the request's MCP session id before the transport is invoked.
Entrance-to-sink chain. Attacker-controlled header -> transports[sessionId] prototype-chain lookup (src/dev_server.ts:287-289 / :394 / :415) -> truthy non-transport value assigned to transport -> await transport.handleRequest(req, res, req.body) at src/dev_server.ts:350 (POST), src/dev_server.ts:406 (GET), src/dev_server.ts:423 (DELETE) -> TypeError: transport.handleRequest is not a function -> caught by the route-level try/catch and passed to respondWithError(res, error, ...) (src/dev_server.ts:240-262), which logs log.exception(...) for status >= 500 and responds HTTP 500 with {"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal server error"},"id":null}.
Observed server-side evidence (from the dynamic run): transport.handleRequest is not a function with the logMessage values Error handling MCP request (POST), Error handling GET SSE stream (GET) and Error handling DELETE request (DELETE). In the POST branch the exception is raised before any session is created, so this is not a session-allocation bug but a pure input-validation/robustness defect in the session lookup.
Scope note (honest impact ceiling). The lookup cannot return another client's real transport, because genuine sessions are keyed by server-generated randomUUID() strings (created at src/dev_server.ts:336-347); the primitive only yields inherited Object.prototype members. Hence no cross-session data access was demonstrated, the process survives each request, and the reproducible harm is limited to: unauthenticated HTTP 500 responses on POST/GET/DELETE, an authorization/state-machine integrity violation (an unauthenticated request is accepted as "session exists"), and exception-level log entries that an anonymous client can generate at will.
Core vulnerable code path:
// src/dev_server.ts:234-235
const mcpServers: { [sessionId: string]: ActorsMcpServer } = {};
const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};Root cause: the session registry is a plain object literal instead of a Map or a null-prototype object, so lookups with an attacker-controlled key resolve inherited Object.prototype members. Both maps should be new Map<string, ...>() or created with Object.create(null), and every lookup should be guarded by Object.hasOwn(...).
// src/dev_server.ts:283-289
const sessionId = req.headers['mcp-session-id'] as string | undefined;
const initializeMessage = extractInitializeMessage(req.body);
let transport: StreamableHTTPServerTransport;
if (sessionId && transports[sessionId]) {
// Reuse existing transport
transport = transports[sessionId];
} else if (!sessionId && initializeMessage) {The POST route (2025-11-25 stateful path) reads the fully client-controlled Mcp-Session-Id header and accepts any truthy prototype-chain lookup as evidence that the session exists. For constructor the expression transports[sessionId] yields the built-in Object constructor, so a function object is assigned to transport. This line is reached without any credential (auth is enforced only in the initialize branch below, src/dev_server.ts:307).
// src/dev_server.ts:412-423
app.delete('/', async (req: Request, res: Response) => {
const sessionId = req.headers['mcp-session-id'] as string | undefined;
const transport = transports[sessionId || ''] as StreamableHTTPServerTransport | undefined;
if (transport) {
log.info('MCP API', {
mth: req.method,
rt: '/',
mcpSessionId: sessionId,
});
try {
await transport.handleRequest(req, res, req.body);Dangerous operation reached through the prototype-chain lookup: transport is whatever the inherited key resolved to (a function), and transport.handleRequest(...) is invoked on it, raising TypeError: transport.handleRequest is not a function. The exception is caught and converted by respondWithError() into HTTP 500 plus a log.exception stack trace. The POST (src/dev_server.ts:350) and GET (src/dev_server.ts:406) routes call the same method.
// src/dev_server.ts:392-398
app.get('/', async (req: Request, res: Response) => {
const sessionId = req.headers['mcp-session-id'] as string | undefined;
const transport = transports[sessionId || ''] as StreamableHTTPServerTransport | undefined;
if (!transport) {
log.softFail('Session not found for GET SSE stream', { mcpSessionId: sessionId, statusCode: 404 });
res.status(404).send('Not Found: Session not found').end();
return;
}Same defect on the SSE route, with the added effect that the intended 'session does not exist' decision (404) is defeated: a prototype-inherited truthy value skips the if (!transport) guard, so the request is processed as if the session were live before the handler crashes with HTTP 500.
POC
Preconditions: the MCP HTTP entry point is reachable (in this repository the dev/standby server started with node dist/dev_server.js or pnpm start, which listens on 127.0.0.1:3001 by default). The attacker needs no Apify API token, no account and no user interaction - the session-table lookups run before (POST) or entirely outside (GET, DELETE) any authentication check.
Step 1 - unauthenticated 500 on POST /. Method POST, endpoint /, header Mcp-Session-Id: constructor (a real session id is not needed), additional headers Content-Type: application/json and Accept: application/json, text/event-stream, JSON-RPC body ({"jsonrpc":"2.0","id":9,"method":"tools/list","params":{}}). Expected and observed result: HTTP 500 with body {"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal server error"},"id":null}, and the server log records transport.handleRequest is not a function with logMessage: "Error handling MCP request". A control request with the same body but no Mcp-Session-Id header returns 400/-32000 (Bad Request: Mcp-Session-Id header is required), and a random valid-format UUID returns 404 Session not found - so the 500 is specific to the prototype-chain hit.
Step 2 - unauthenticated 500 on DELETE /. Method DELETE, endpoint /, header Mcp-Session-Id: toString. Expected and observed result: HTTP 500 and server log Error handling DELETE request / transport.handleRequest is not a function.
Step 3 - unauthenticated 500 on GET / (SSE route). Method GET, endpoint /, header Mcp-Session-Id: valueOf. Expected and observed result: HTTP 500 and server log Error handling GET SSE stream / transport.handleRequest is not a function. The same holds for __proto__ (which resolves to a non-callable object and throws on factory-style invocation in related code paths) and for any other inherited member that resolves to a truthy value.
Step 4 - amplification. Repeat step 1 in a loop without credentials: each iteration produces one HTTP 500 and one log.exception entry containing a full stack trace, so an anonymous client can generate exception-level log traffic and error-monitoring noise at will (no rate limiting exists on the dev server for this path).
Reproduction honesty note: the technique does not yield another client's session or data. Genuine sessions are stored under server-generated randomUUID() keys (src/dev_server.ts:336-347), so the only obtainable values are inherited Object.prototype members; the demonstrated outcome is the unauthenticated exception/500, the bypass of the session-existence decision, and the exception-log flooding. Any test must be performed against a local instance you own.
Impact
Availability/robustness: an unauthenticated client can deterministically force an uncaught TypeError and an HTTP 500 response on all three session routes (POST /, GET /, DELETE /) with a single header, and can repeat it to produce exception-level log entries with full stack traces at will (log/monitoring flooding, degraded alert signal). Integrity/authorization: the "session exists" decision is made on a truthy prototype-chain value, so an unauthenticated request is admitted into the session-reuse code path reserved for established sessions and the attacker-supplied string is injected as the request's MCP session id (injectMcpSessionId, src/dev_server.ts:377-379) before the transport is invoked - a state/authorization-integrity violation, even though the request subsequently fails. Confidentiality: none demonstrated - the generic 500 body discloses no internal detail (only the server-side log holds the stack trace), and real transports remain unreachable because session ids are server-generated UUIDs. Scope: the defect is in the repository's HTTP entry point (src/dev_server.ts, createExpressApp()); the hosted production transport for mcp.apify.com lives in a separate internal repository, so this report concerns the published/deployed HTTP entry implementation present in this code base. The overall CVSS v3.1 base score is 6.4 (medium) because no confidentiality or sustained availability impact was demonstrated, while the underlying access-control/state-machine defect is genuine and remotely triggerable without credentials.
Remediation
- Replace the plain-object session registry with a
Map(orObject.create(null)) increateExpressApp()(src/dev_server.ts:234-235):const mcpServers = new Map<string, ActorsMcpServer>();andconst transports = new Map<string, StreamableHTTPServerTransport>();, then usetransports.get(id)/transports.set(id, value)/transports.delete(id). If plain objects must be kept, guard every read:const transport = Object.hasOwn(transports, sessionId) ? transports[sessionId] : undefined;(never use theinoperator or a bare truthiness test). 2) Validate the session id format before use - require a UUID (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i) in a small helper shared by the POST, GET and DELETE routes, and answer 400/404 for anything else, soconstructor,toString,valueOfand__proto__never become looked-up keys. 3) Keep the transport type guarantee: after the lookup, assert the value is one of the server's own transports (e.g. a privateWeakSetof transports registered inonsessioninitialized) instead of relying on a cast. 4) Harden the error path so unauthenticated input cannot produce 5xx noise: return 404/400 for lookup failures and rate-limit or samplelog.exceptionon this route; keep the generic response body (do not add the error message to it). 5) Regression tests: for each of POST/GET/DELETE, assert thatMcp-Session-Id: constructor,toString,valueOfand__proto__return 400 or 404 - never 500 - and that nolog.exceptionis emitted, plus a test that the session maps contain no prototype-accessible entries.
Disclosure Notes
Verification status: dynamically confirmed against the shipped implementation (npm @apify/actors-mcp-server@0.15.6-beta.1, whose dist is byte-identical to this repository's src at master commit ee87bb7) on Node.js v22.14.0. Observed results: POST / with Mcp-Session-Id: constructor -> HTTP 500 -32603 and log transport.handleRequest is not a function; DELETE / with toString -> HTTP 500 (Error handling DELETE request); GET / with valueOf -> HTTP 500 (Error handling GET SSE stream); control requests without the header -> 400/-32000, with a random UUID -> 404 Session not found. Patched version: none confirmed (patched_versions is reported as "to be confirmed"; no fix exists at the audited commit). Exposure note: the in-repository HTTP server binds 127.0.0.1 by default, which limits remote reachability of that specific process; the production HTTP transport for mcp.apify.com is implemented in a separate internal repository, so this report covers the published/self-hosted entry implementation shipped in this code base. Severity note for transparency: the managed severity label for this issue is "high" (it is a remotely triggerable, unauthenticated defect), while the CVSS v3.1 base score computed strictly from the demonstrated effects is 6.4 (medium) because confidentiality and sustained availability impacts could not be shown. No public advisory or CVE identifier was found for this defect, and no reference links beyond the project repository were verified. Recommend coordinated private disclosure through the project's SECURITY.md channels (security@apify.com or GitHub private vulnerability reporting) and a patch release before public write-ups. Re-testing should be limited to instances you own, using credential-free requests.
Supplemental Information
Affected products
- Ecosystem: npm
- Package name: @apify/actors-mcp-server (apify/apify-mcp-server)
- Affected versions: 0.15.6-beta.1 and earlier releases that ship the same
createExpressApp()session lookup (verified against npm 0.15.6-beta.1 and repository master commit ee87bb7); exact lower bound to be confirmed - Patched versions: to be confirmed
Severity
- Scoring method: CVSS v3.1
- Score: 6.4
- Vector string: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:L
Weaknesses
- CWE: CWE-248 Uncaught Exception (root cause: CWE-1321 prototype-chain property lookup on an externally controlled key; related CWE-20 improper input validation). Managed label: high; demonstrated CVSS v3.1 base score 6.4.