Conversation
Prevent unauthenticated DoS by rejecting POSTs to /mcp that lack both an MCP session ID and Authorization header before parsing the JSON body. Validate Bearer tokens prior to creating StreamableHTTPServerTransport during initialization and store session data only after successful token validation (addresses AAP-70224). Update existing E2E tests to expect 401 for unauthenticated requests and add a new security E2E test that mocks the AAP service to verify fast rejection of unauthenticated/invalid-token requests and successful session creation for valid tokens.
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||
jameswnl
left a comment
There was a problem hiding this comment.
Looks good — the two-layer defense is well architected and directly addresses AAP-70224. A few observations:
[medium] Path matching is overly broad (src/index.ts)
if (req.method === "POST" && req.path.includes("/mcp")).includes("/mcp") would match any path containing that substring (e.g. /something/mcp-unrelated). Consider tightening to something like req.path === "/mcp" || req.path.endsWith("/mcp") to match only the actual MCP routes.
[low] Duplicated JSON-RPC error response structure (src/index.ts)
The 401 error response { jsonrpc: "2.0", error: { code: -32000, message: "..." }, id: ... } is constructed inline in three places (middleware, missing token check, invalid token check). Consider extracting a small helper to reduce duplication.
[low] Timing assertion may be flaky (tests/security/unauthenticated-dos-prevention-e2e.test.ts)
expect(responseTime).toBeLessThan(100) — while 100ms is generous, timing-based assertions are sensitive to CI load. Worth keeping an eye on if it starts flaking.
Addresses https://redhat.atlassian.net/browse/AAP-70224
Prevent unauthenticated DoS by rejecting POSTs to /mcp that lack both an MCP session ID and Authorization header before parsing the JSON body. Validate Bearer tokens prior to creating StreamableHTTPServerTransport during initialization and store session data only after successful token validation (addresses AAP-70224). Update existing E2E tests to expect 401 for unauthenticated requests and add a new security E2E test that mocks the AAP service to verify fast rejection of unauthenticated/invalid-token requests and successful session creation for valid tokens.