fix(cors): set Vary: Origin on the public no-credential branch - #9814
Conversation
The public CORS branch fires only when the request carried an `Origin` and sets
`Access-Control-Allow-Origin: *`, but never set `Vary: Origin`. So the response
headers differ by whether an Origin was present, yet nothing told a shared cache
that — a cache could serve the Origin-bearing response (with the ACAO header) to a
later no-Origin request, or vice versa. The credentialed branch already appends
`Vary: Origin`; the public branch just omitted it.
Append `Vary: Origin` on the public branch with `{ append: true }`, identical to
the credentialed branch, so any Vary set elsewhere is preserved. No change to
which origins are allowed, to Access-Control-Allow-Credentials (still absent on
this branch), or to any cache header.
Closes JSONbored#9712
|
Warning ⏸️ LoopOver review result - manual review recommendedReview updated: 2026-07-29 11:02:43 UTC
Review summary Nits — 2 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. Decision record
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
🚨 Contributor flagged. Click here for more info: Superagent Dashboard |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9814 +/- ##
==========================================
+ Coverage 77.18% 77.92% +0.73%
==========================================
Files 283 284 +1
Lines 59729 62211 +2482
Branches 6696 7501 +805
==========================================
+ Hits 46104 48477 +2373
- Misses 13342 13363 +21
- Partials 283 371 +88
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Held for manual review: the gate and required CI are green, but GitHub reports this pull request's mergeable state as |
What & why
The CORS middleware in
createApp()has two branches. The public no-credential branch fires whenorigin && isPublicNoCredentialRoute(path)and setsAccess-Control-Allow-Origin: *,Access-Control-Allow-Headers/Methods/Max-Age— but noVary. Because the branch is guarded byorigin &&, the response headers differ depending on whether the request carried anOrigin(with one → the ACAO/allow headers; without → none). Nothing tells a shared cache that, so a cache keyed only on URL could serve the Origin-bearing response to a later no-Origin request, or vice versa. The credentialedelsebranch already appendsVary: Origin; the public branch simply omitted it.The fix
Append
Vary: Originon the public branch with{ append: true }— the identical call the credentialed branch uses — so anyVaryset elsewhere is preserved rather than overwritten. No change to which origins are allowed, toAccess-Control-Allow-Credentials(which stays absent on this branch), or to anyCache-Controlvalue.Tests (
test/unit/routes-cors.test.ts)GET /healthwith anOriginreturnsAccess-Control-Allow-Origin: *and aVarycontainingOrigin(fails onmain).GET /v1/public/statsand theGET /v1/public/github/repos/:owner/:repo/statsbadge route (fails onmain).GET /healthwith noOriginsets noAccess-Control-Allow-Origin— pinning that the response genuinely varies, which is what makes theVaryload-bearing.Vary: Origin(appended, not duplicated) plusAccess-Control-Allow-Credentials: true.Validation
npm run typecheckgreen;npm run ui:openapi:checkclean (a response header is not part of the schema); the CORS suite (11 tests) green.src/api/routes.tsis 100% (the single added header call).git diff --check <base> HEADclean; diff is two files, no schema/migration change.Closes #9712