← Back to Pull requests

fix(auth): scope well-known CORS to /.well-known/* only #285

Closed
unknown closed this pull request without merging on Oct 14, 2026 10:20 UTC
View on GitHub
unknown unknown commented on Oct 13, 2026 11:20 UTC
Author

Problem

With authorization.enabled, src/routes/well-known.ts registered @fastify/cors (origin: true) inside a fastify-plugin wrapper, so CORS applied to the whole app:

  • any Origin was reflected on the application's own routes;

  • preflights for POST /mcp were answered with GET, HEAD, OPTIONS only and without the Mcp- headers, so browsers blocked the request;

  • an app that registered its own @fastify/cors failed to start with FST_ERR_DEC_ALREADY_PRESENT (corsPreflightEnabled).
  • Fix

  • The well-known routes are registered in an encapsulated child context (plain register, not fastify-plugin) together with a small onRequest CORS hook and an OPTIONS /.well-known/ route. CORS now covers /.well-known/ only.

  • @fastify/cors is no longer used there. Moving it into the child context was not enough: it calls decorateRequest('corsPreflightEnabled'), which still clashes with an app-level registration (child contexts inherit the parent's decorators), and it adds an OPTIONS route, which is global and would keep answering preflights for every path. It moves to devDependencies because only the tests use it.

  • CORS for /mcp is left to the application. The README has a new CORS section with an @fastify/cors example that allows GET/POST/DELETE and the Authorization / Mcp- headers, and exposes Mcp-Session-Id.
  • The auth preHandler still skips /.well-known/ (it matches on the URL, and the child context inherits the root hook).

    Tests

    New tests in test/well-known-routes.test.ts:

  • well-known routes still send Access-Control-Allow-Origin;

  • an application route gets no reflected origin, for a simple GET or for a preflight;

  • an app that registers its own @fastify/cors before the plugin (authorization enabled) starts, its CORS policy applies to /mcp, and the well-known metadata stays public with its own CORS.
  • Breaking change

    Apps that relied on the plugin's leaked CORS headers on their own routes, or on /mcp, no longer get them and need to register @fastify/cors themselves (see README).

    Fixes #258

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01UF4S3w7iA83V9DVsasLJzM

    Diff: 278 lines (+208 / -70) across 3 files Reviewer: rozzilla Review duration: 1379m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.63) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.63 · 278 lines diff across 3 files
    0.63
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.337
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.063
    Real PR Conversation Timeline
    1 comments
    "Review active on #285"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.8% (MEDIUM) · Higher = larger blast radius
    62.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.8% · Safe to merge
    24.8%