Skip to content

fix(api): strip stale Access-Control-Allow-Origin in addCorsHeaders - #431

Merged
limaronaldo merged 1 commit into
mainfrom
rm/fix-cors-stale-acao
Aug 11, 2026
Merged

fix(api): strip stale Access-Control-Allow-Origin in addCorsHeaders#431
limaronaldo merged 1 commit into
mainfrom
rm/fix-cors-stale-acao

Conversation

@limaronaldo

Copy link
Copy Markdown
Owner

Follow-up (MED) to #427 (352412d).

Problem

addCorsHeaders re-applied corsHeadersFor with Headers.set, but when the evaluated origin is not allowed, no Access-Control-Allow-Origin is computed — so a stale/upstream ACAO (and Access-Control-Allow-Credentials) already on the response survived and could leak an old origin.

Fix

Delete Access-Control-Allow-Origin and Access-Control-Allow-Credentials from the response headers before applying the computed CORS headers. Guarantees at most one correct value and no ACAO for disallowed origins (secure by default).

Tests

Added unit tests to cors.test.ts:

  • stale ACAO + allowed origin → only the correct value emitted (no duplicate)
  • stale ACAO + disallowed origin → ACAO stripped (null)
  • stale Allow-Credentials + disallowed origin → both stripped

Verified the new leak tests fail on the pre-fix code and pass after.

Verification

  • tsc --noEmit: clean
  • Package suite: no regression vs baseline (identical set of pre-existing Playwright/CUA failures; +4 passing CORS tests).

…ddCorsHeaders

Follow-up to #427. addCorsHeaders re-applied corsHeadersFor via
Headers.set, but when the evaluated origin is not allowed no ACAO is
computed, so a stale/upstream Access-Control-Allow-Origin (and
Allow-Credentials) survived on the response and could leak. Delete both
CORS headers before re-applying, guaranteeing at most one correct value
and no ACAO for disallowed origins.
@limaronaldo
limaronaldo merged commit a634679 into main Aug 11, 2026
4 checks passed
@limaronaldo
limaronaldo deleted the rm/fix-cors-stale-acao branch August 11, 2026 03:00
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