HTTP boundary passes websocket scopes to the inner app unguarded #41

Open
opened 2026-11-20 01:52:30 +00:00 by svc-agent-writer · 1 comment

Problem

The HTTP Boundary in src/attention_mind_mcp/mcp_adapter.py passes every non-http ASGI scope straight to the inner app (mcp_adapter.py:152-154 at PR #40 head 99bbcf65). That includes websocket scopes. The Host check, the Origin refusal and the bearer check from #39 apply only to http scopes.

Today a websocket upgrade to /mcp, /mcp/ or / is refused with 403. A raw-socket probe of the served app showed this during the PR #40 security review. The refusal comes from a framework detail: fastmcp registers /mcp as a Starlette Route, and a Route matches only http scopes. A later fastmcp or Starlette version that adds a websocket route or a Mount would expose that route with no Host, Origin or bearer check.

Requirement

The Boundary refuses every scope type except http and lifespan, before it calls the inner app. lifespan must still pass through, because it starts the session manager.

Acceptance criteria

  • A websocket scope gets websocket.close with code 1008, and the inner app is never called.
  • A lifespan scope still reaches the inner app, and the served app starts.
  • A transport test sends a websocket upgrade to /mcp on the real served app and sees a refusal, with and without a bearer, a foreign Host or an Origin header.
  • A unit test drives the Boundary with a raw websocket scope and asserts that the inner app is not called.

Notes

  • Precedent: messages-mind src/messages_mind_mcp/face.py:167-174 does this.
  • Source: the spec for #39 lists this as open risk 4, deferred to a follow-up. The PR #40 security review rated it info-level hardening, not a live gap.
  • Related: #39, PR #40.

Human act

ruling: the operator moves #41 to ready-for-agent after #35 merges (CONV-40)

Blocked by

  • #35 — DD-469 #6 child 7/7. Operator ruling 2026-11-20: land this hardening after the #6 chain, so its merge does not force spec rebaselines mid-chain.

Filed under: operator-word-d982c2768589

## Problem The HTTP `Boundary` in `src/attention_mind_mcp/mcp_adapter.py` passes every non-`http` ASGI scope straight to the inner app (`mcp_adapter.py:152-154` at PR #40 head 99bbcf65). That includes `websocket` scopes. The Host check, the Origin refusal and the bearer check from #39 apply only to `http` scopes. Today a websocket upgrade to `/mcp`, `/mcp/` or `/` is refused with 403. A raw-socket probe of the served app showed this during the PR #40 security review. The refusal comes from a framework detail: fastmcp registers `/mcp` as a Starlette `Route`, and a `Route` matches only `http` scopes. A later fastmcp or Starlette version that adds a websocket route or a `Mount` would expose that route with no Host, Origin or bearer check. ## Requirement The `Boundary` refuses every scope type except `http` and `lifespan`, before it calls the inner app. `lifespan` must still pass through, because it starts the session manager. ## Acceptance criteria - A `websocket` scope gets `websocket.close` with code 1008, and the inner app is never called. - A `lifespan` scope still reaches the inner app, and the served app starts. - A transport test sends a websocket upgrade to `/mcp` on the real served app and sees a refusal, with and without a bearer, a foreign Host or an Origin header. - A unit test drives the `Boundary` with a raw `websocket` scope and asserts that the inner app is not called. ## Notes - Precedent: messages-mind `src/messages_mind_mcp/face.py:167-174` does this. - Source: the spec for #39 lists this as open risk 4, deferred to a follow-up. The PR #40 security review rated it info-level hardening, not a live gap. - Related: #39, PR #40. ## Human act ruling: the operator moves #41 to ready-for-agent after #35 merges (CONV-40) ## Blocked by - #35 — DD-469 #6 child 7/7. Operator ruling 2026-11-20: land this hardening after the #6 chain, so its merge does not force spec rebaselines mid-chain. Filed under: operator-word-d982c2768589
Author
Member

This was generated by AI during triage.

Triage: ready-for-human (parked until #35 merges)

Category: enhancement (defence in depth; this repo has no category labels)

Summary: the HTTP Boundary must refuse every ASGI scope type except http and lifespan before it calls the inner app.

Current behaviour: Boundary passes every non-http scope to the inner app. A websocket scope therefore skips the Host check, the Origin refusal and the bearer check from #39. Today no websocket route exists: the PR #40 security probe sent upgrades to /mcp, /mcp/ and / on the served app, with and without a bearer, a foreign Host or an Origin header, and every one got 403. The refusal comes from the framework, because fastmcp's /mcp route matches only http scopes.

Desired behaviour: lifespan still reaches the inner app. Every other non-http scope gets websocket.close with code 1008 at the Boundary, and the inner app is never called.

Key interfaces:

  • Boundary.__call__(scope, receive, send): the scope-type dispatch at its top.
  • Precedent: messages-mind's Face.__call__ does the same and counts the refusal under a protocol reason.

Acceptance criteria:

  • A unit test drives Boundary with a raw websocket scope and asserts websocket.close code 1008, with the inner app not called.
  • A unit test shows a lifespan scope still reaches the inner app.
  • A transport test sends a websocket upgrade to /mcp on the real served app and sees a refusal with and without a bearer, a foreign Host and an Origin header.
  • Existing unit and transport suites stay green.

Out of scope: CORS, X-Forwarded-Host, any change to the #39 Host and Origin rules, and .woodpecker/.

Why ready-for-human now: the change is bounded and agent-shaped. It touches the network trust boundary (CONV-40 rule 3), and it closes no live gap. The operator ruled to land it after the #6 chain: every attention merge moves main and forces a rebaseline of any spec waiting for dispatch. When #35 merges, move this issue to ready-for-agent.

Evidence: the #39 spec scopes websocket handling out (its open risk 4 asks for a follow-up only if an upgrade is not refused). The PR #40 security review recorded the probe.

> *This was generated by AI during triage.* ## Triage: ready-for-human (parked until #35 merges) **Category:** enhancement (defence in depth; this repo has no category labels) **Summary:** the HTTP `Boundary` must refuse every ASGI scope type except `http` and `lifespan` before it calls the inner app. **Current behaviour:** `Boundary` passes every non-`http` scope to the inner app. A `websocket` scope therefore skips the Host check, the Origin refusal and the bearer check from #39. Today no websocket route exists: the PR #40 security probe sent upgrades to `/mcp`, `/mcp/` and `/` on the served app, with and without a bearer, a foreign Host or an Origin header, and every one got 403. The refusal comes from the framework, because fastmcp's `/mcp` route matches only `http` scopes. **Desired behaviour:** `lifespan` still reaches the inner app. Every other non-`http` scope gets `websocket.close` with code 1008 at the `Boundary`, and the inner app is never called. **Key interfaces:** - `Boundary.__call__(scope, receive, send)`: the scope-type dispatch at its top. - Precedent: messages-mind's `Face.__call__` does the same and counts the refusal under a `protocol` reason. **Acceptance criteria:** - [ ] A unit test drives `Boundary` with a raw `websocket` scope and asserts `websocket.close` code 1008, with the inner app not called. - [ ] A unit test shows a `lifespan` scope still reaches the inner app. - [ ] A transport test sends a websocket upgrade to `/mcp` on the real served app and sees a refusal with and without a bearer, a foreign Host and an Origin header. - [ ] Existing unit and transport suites stay green. **Out of scope:** CORS, `X-Forwarded-Host`, any change to the #39 Host and Origin rules, and `.woodpecker/`. **Why ready-for-human now:** the change is bounded and agent-shaped. It touches the network trust boundary (CONV-40 rule 3), and it closes no live gap. The operator ruled to land it after the #6 chain: every attention merge moves main and forces a rebaseline of any spec waiting for dispatch. When #35 merges, move this issue to `ready-for-agent`. **Evidence:** the #39 spec scopes websocket handling out (its open risk 4 asks for a follow-up only if an upgrade is not refused). The PR #40 security review recorded the probe.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/attention-mind-mcp#41
No description provided.