Skip to content

fix(auth): allow trailing slashes on MCP CSRF exemptions - #7533

Merged
bokelley merged 2 commits into
mainfrom
fix/mcp-csrf-trailing-slash
Sep 15, 2026
Merged

bokelley merged 2 commits into
mainfrom
fix/mcp-csrf-trailing-slash

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • normalize one optional trailing slash before exact and per-tenant MCP CSRF exemptions
  • let /mcp/ reach bearer authentication instead of returning 403 cookie_expired
  • keep double-slash and appended-path near misses protected

Production evidence

POST https://test-agent.adcontextprotocol.org/mcp/ without credentials currently returns 403 CSRF validation failed before the training-agent authenticator can emit its 401 WWW-Authenticate challenge. The documented CLI endpoint includes that trailing slash.

The member OAuth surface at https://agenticadvertising.org/mcp remains healthy through RFC 9728/RFC 8414 discovery, dynamic client registration, PKCE authorization construction, and redirect to WorkOS; this PR fixes the separate host-routed endpoint regression.

Verification

  • npx vitest run server/tests/unit/csrf-middleware.test.ts --config server/vitest.config.ts (64 passed)
  • npm run typecheck
  • git diff --check

No changeset: operational server fix only.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Sep 15, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — CSRF trailing-slash normalization fix.

This PR adds trailing-slash normalization to the CSRF exemption check (server/src/middleware/csrf.ts:15) so that /mcp/ and //mcp/ reach their bearer/RFC-9421 authenticators instead of being 403'd by the double-submit-cookie middleware. The change only matches alternate spellings of already-exempt handlers — no cookie-authed route is newly exempted — and near-misses (/mcp//, /mcp/extra) remain protected, with test coverage asserting 403.

Server-middleware-only change; no protocol surface (static/schemas/source/, docs/reference/, dist/**) touched, so no changeset is required. No Critical/High/Medium findings.

Gate checks: no no-auto-approve team match; gated_paths is false; high_risk is false; no prior decision. review_decision is REVIEW_REQUIRED but the gated-paths gate (row 2) only applies when gated_paths is true — it is false here. No decision-table rows 1–8 fire, so this falls through to row 9: approve.

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — clean CSRF fix for MCP route trailing-slash normalization.

This PR narrowly normalizes one optional trailing slash before the bearer/RFC 9421-authed MCP exact and per-tenant exemptions so /mcp/ reaches its bearer authenticator instead of returning a 403. Verified:

  • Normalization is confined to MCP route families; byte-exact matching is preserved for /token, /register, etc.
  • Fail-closed behavior holds for /mcp// and appended paths.
  • The fix is covered by an end-to-end test wiring the real csrfProtection to the real router.
  • No changeset required — this is a server-only operational change, not a change to the published protocol surface (static/schemas/source/**, normative docs, dist artifacts).

No Critical/High/Medium findings. This is a server-only change (server/**) with no schema/docs/spec surface touched, so schema↔docs coherence, changeset scope, oneOf discriminator, artifact immutability, and 3.1.x-patch gates do not apply. gated_paths is false; high_risk is false; no no-auto-approve team match. No blocking or escalation triggers fire — falls through to row 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant