← Back to Pull requests

fix(gateway): allow the document write under named-origin CORS #6038

Open
unknown opened this pull request with 296 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 12, 2026 15:48 UTC
Author

Description

Problem

The list policy of --cors-allowed-origins allowed GET, POST, PATCH, DELETE and OPTIONS. It allowed the content-type, authorization, Anthropic and trace headers, and exposed the request id and the trace context. A browser client under a named origin could not replace the tenant rate-limit document. Its preflight asked for PUT and If-Match and got neither, and an answer's ETag and revision were unreadable.

Solution

The list policy allows PUT and If-Match. It exposes ETag and the revision header under the one name the document route defines, which its parent module now reads. The wildcard policy was open already. The list policy covers every route, so a named origin may now send PUT and If-Match anywhere. A named origin is operator-configured. One test drives a preflight and a plain request through the layer.

Changes

  • model_gateway/src/server.rs: create_cors_layer allows PUT and If-Match and exposes ETag and the revision header.

  • model_gateway/src/server.rs: the test configured_cors_allows_the_document_write.

  • model_gateway/src/server/rate_limit_document.rs: the revision header constant is visible to the server module.
  • Test Plan

  • cargo test -p smg --lib -- server::: 62 passed, three runs.

  • cargo test -p smg --test security_tests -- rate_limit_document: the document route's tests pass once.

  • cargo clippy -p smg --all-targets -- -D warnings, cargo fmt --check and cargo doc -p smg with warnings denied: clean.

  • Three mutants on the list policy, server.rs restored after each. PUT dropped: the new test red. If-Match dropped: red. ETag and the revision header dropped: red.

  • Reviewed on this head: ACCEPT, the review of 2026-11-12T13:33:36Z. A green second gate, the test gate of 2026-11-12T14:12:09Z.
  • Numbers

    | measure | before | after |
    |---|---|---|
    | methods the list policy allows | 5 | 6 |
    | request headers the list policy allows | 6 | 7 |
    | response headers the list policy exposes | 4 | 6 |
    | server module unit tests | 61 | 62 |
    | mutants of the list policy the suite catches | 0 of 3 | 3 of 3 |

    The table shows the document write and its headers under named-origin CORS, each pinned by a test.

    Release note

    A browser client under a named CORS origin can replace the tenant rate-limit document and read its ETag and revision.

    Diff: 296 lines (+222 / -74) across 3 files Reviewer: claude[bot] Review duration: 10m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 296 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.341
    Real PR Conversation Timeline
    1 comments
    "Review active on #6038"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    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: 40.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 21.3% · Safe to merge
    21.3%