1. Introduction

Agent-built HTTP APIs usually ship with a CORS layer, configured either as a list of allowed Origin values or as a regular expression. The three most common middleware stacks in agent-built backends are expressjs/cors, Starlette’s CORSMiddleware (which FastAPI re-exports) and Flask-CORS. All three advertise the same feature but document different matching rules: exact membership or regex, fullmatch or prefix or substring regex, and reflecting the request Origin or echoing a configured string. Code agents often move a CORS configuration from one framework to another when they port a service. We ask a narrow question: given the same request Origin and the same configuration intent, does each middleware set Access-Control-Allow-Origin (ACAO), and to what value?

Each library documents its own options [1–3]. The Fetch standard [4] defines how browsers evaluate ACAO and forbids * together with credentials. Work on CORS misconfiguration has measured deployed servers, for example reflected origins and null trust; we use that literature only for context and do not claim prevalence numbers from it. We found no published measurement that runs one shared Origin corpus through these three middlewares and reports per-case disagreement. Our method is differential testing in the sense of McKeeman [5].

3. Method

Subjects and versions. expressjs/cors 2.8.6 (Express 4.21.2 installed alongside) on Node v24.22.1. Starlette 1.10.0 CORSMiddleware. Flask-CORS 6.0.5 on Flask 3.1.3. Both Python libraries ran on CPython 3.13.5. The versions are recorded in results/versions.txt of the supporting folder.

Harness. gen_cases.py writes cases.json (21 cases; Appendix A). js/run_express.mjs builds cors(options) for each case and calls it directly as connect-style middleware, with a minimal mock request (method GET, optional origin header) and a mock response that records setHeader calls. Express’s router is not in the loop. py/run_py.py builds a fresh Starlette app with CORSMiddleware and a fresh Flask app with CORS(app, …) for each case, then sends one GET through each framework’s test client. analyze.py compares the three ACAO values as strings. A case counts as agreeing only if all three are identical, where “absent” is itself a value.

Option mapping. A list of origins maps to origin: [...] (Express), allow_origins=[...] (Starlette) and origins=[...] (Flask-CORS). * maps to origin: "*", allow_origins=["*"] and origins="*". A regex case maps to origin: new RegExp(p) (Express), allow_origin_regex=p (Starlette) and origins=p (Flask-CORS treats a string with regex metacharacters as a pattern). Credentials map to credentials: true, allow_credentials=True and supports_credentials=True. Every other option is left at its default. The mapping is part of the comparison surface: it is what a developer or agent writes when porting a configuration.

Reproduce. From a clone of the supporting repository:

git checkout 5f4ae702293679a0583a2bf40ce5ab8f4279fde7
cd cors-origin/js && npm ci && cd ..
python3 -m venv .venv && .venv/bin/pip install flask==3.1.3 flask-cors==6.0.5 starlette==1.10.0 httpx
PY=.venv/bin/python ./run_all.sh

Folder at the pinned commit: https://github.com/buildngrowsv/pubroot-[REDACTED_SECRET]-origin/

On 2026-11-09 we re-ran run_all.sh from a clean export of that commit. results/express.json, results/py.json and results/summary.json came out byte-identical to the committed files.

4. Results

The middlewares disagreed on 8 of 21 cases (Appendix B). All three agreed on the 13 others: exact allow and deny, trailing slash on either side, explicit :443, scheme mismatch, subdomain not listed, null listed and not listed, the two anchored subdomain-regex cases, and exact origin with credentials. The eight disagreements fall into four groups.

4.1 Regex anchoring (cases 15–16). Starlette calls allow_origin_regex.fullmatch(origin), Flask-CORS calls pattern.match(origin) (anchored at the start only), and expressjs/cors calls RegExp.prototype.test (unanchored). We read these calls in the installed sources, and they match the observed outputs. With pattern https://app\.example\.com, the origin https://app.example.com.evil.com was admitted and reflected by Express and Flask-CORS and rejected by Starlette. With the unanchored pattern app\.example\.com, only Express admitted it: Flask-CORS’s start anchor fails because the origin begins with https://.

4.2 Wildcard and credentials (cases 4, 5, 18). With * and no credentials, Express and Starlette sent * while Flask-CORS reflected the request Origin, because its send_wildcard default is False. With * and credentials, Express sent ACAO: * together with Access-Control-Allow-Credentials: true, a pair the Fetch standard makes browsers reject. Starlette and Flask-CORS instead reflected the request origin with credentials true, which admits any origin with credentials. All three sent Access-Control-Allow-Credentials: true in both credentials cases (17 and 18). With * and no Origin header (case 5), Express and Flask-CORS still sent *, while Starlette sent nothing.

4.3 Missing Origin (case 19). With an allowlist of one origin and no Origin header, Flask-CORS sent ACAO: https://app.example.com (its always_send default is True), while the other two sent nothing.

4.4 Case sensitivity (cases 20–21). Flask-CORS compares configured literal origins case-insensitively (casefold) and reflected the request’s original casing (HTTPS://app.example.com, https://APP.example.com). Express and Starlette compared exactly and rejected both. Browsers serialise origins in lowercase, so this mostly matters to non-browser clients and caches. We do not claim a browser-exploitable effect.

5. Real-world sample: do public regexes depend on fullmatch?

The core cases are synthetic, so we added one cheap check on real configurations. On 2026-11-09 we ran the GitHub code search allow_origin_regex language:python and took the first 60 results (60 files, 60 distinct repositories). We fetched each file at its default branch through the GitHub contents API and extracted string-literal arguments to allow_origin_regex=. Of the 60 files, 43 contained at least one literal and 17 passed a variable or config value, which we skipped. Deduplication left 30 unique patterns. One (*) is not a valid Python or JavaScript regex, which left 29 to run.

For each pattern we generated one legitimate origin that the pattern fully matches. We used a fixed preference list (http://localhost:3000, http://localhost:5173, http://127.0.0.1:5170, http://localhost) and then the first fully matching host-like string enumerated by the exrex library. We then built two probes: a suffix probe (legitimate origin + .evil.test, a host an attacker can register) and an unrelated probe (https://evil.test). Each probe went through the same three runners as the core cases. The run was repeated and produced identical outputs.

Results (Appendix C): every legitimate probe was admitted by all three middlewares, apart from the malformed https://* discussed below. On the 28 suffix probes, 8 were rejected by all three (exactly the 8 patterns anchored ^…$), 5 were admitted by all three (patterns that themselves end in or are built from .*), and 15 were rejected by Starlette but admitted by both Express and Flask-CORS. The unrelated probe was admitted by all three for 3 patterns (.*, https?://.*, http.*?://.*). The malformed pattern https://*, whose /* means “zero or more slashes”, was rejected by Starlette for every real origin but admitted every https: origin in Express and Flask-CORS, https://evil.test included.

Interpretation: 15 of the 28 testable real patterns are safe as written only because Starlette uses fullmatch. Hypothesis: an agent that ports such a FastAPI configuration to Express or Flask-CORS without adding anchors will widen the allowlist to attacker-registrable suffix hosts. We did not measure how often such ports happen.

6. Threats to validity

  • Synthetic core cases. The 21 cases were written by us to probe documented edge cases; they are not drawn from traffic. They show that behaviours differ, not how often each difference matters in deployments.
  • No browser, no preflight. We sent simple GET requests through test clients or mock objects. We did not send OPTIONS preflights, so Access-Control-Allow-Methods/-Headers and preflight-specific code paths (for example Starlette’s preflight_explicit_allow_origin) are untested. Browser enforcement is reasoned from the Fetch standard, not observed.
  • Express harness. expressjs/cors was called directly with mock objects rather than mounted on a listening Express server. The middleware sets headers itself, so we expect the same values, but we did not verify through a socket.
  • Option mapping. The three APIs are not isomorphic; another reasonable mapping (for example Flask-CORS with send_wildcard=True) changes cases 4 and 5. We used defaults on purpose because agents tend to keep them.
  • Single versions. One version per library; behaviour may change across releases.
  • Sample bias. GitHub search ranking is opaque and not stable, and 60 results is small. Many sampled repositories are hobby projects; several patterns target localhost. The sample tests matcher semantics on real pattern strings and does not estimate how widely any weakness occurs. Probe origins were generated mechanically, and a few are unusual-looking (for example https://a.usefleet-ai, which the pattern’s unescaped . permits). We report repository names nowhere and redact project-specific host labels as <site>. The full list, with labels, is kept by the authors and is not needed to reproduce the matcher behaviour, since only the anchoring structure matters.
  • Sample code location. The sample harness is not in the pinned folder. It reuses the pinned runners unchanged, feeding them cases.json-format entries {origin, options:{origin:"__REGEX__", origin_regex:<pattern>}}.

7. Conclusion

On one shared case set, three widely used CORS middlewares disagree on 8 of 21 cases. The differences come from regex anchoring, wildcard-with-credentials handling, default reflection, missing-Origin behaviour and case folding. In a sample of 30 real FastAPI/Starlette patterns, about half rely on Starlette’s fullmatch to reject suffix-extended hosts. CORS configurations should be treated as framework-specific: re-anchor regexes (^…$) when porting, and re-test the emitted header rather than the configuration text.

Appendix A–B. Cases and full verdict matrix

Each row is one case from cases.json. Cells give the emitted Access-Control-Allow-Origin value; “—” means the header was absent. “Configured allow” is the shared intent, mapped per §3.

#CaseRequest OriginConfigured allowexpressjs/corsStarletteFlask-CORSAgree
1exact_allowhttps://app.example.comhttps://app.example.com, https://other.example.comhttps://app.example.comhttps://app.example.comhttps://app.example.comyes
2exact_denyhttps://evil.example.comhttps://app.example.com———yes
3exact_allow_otherhttps://other.example.comhttps://app.example.com, https://other.example.comhttps://other.example.comhttps://other.example.comhttps://other.example.comyes
4star_allowhttps://app.example.com***https://app.example.comno
5star_null(none)**—*no
6trail_slash_reqhttps://app.example.com/https://app.example.com———yes
7trail_slash_cfghttps://app.example.comhttps://app.example.com/———yes
8port_mismatchhttps://app.example.com:443https://app.example.com———yes
9http_vs_httpshttp://app.example.comhttps://app.example.com———yes
10subdomainhttps://api.app.example.comhttps://app.example.com———yes
11null_in_listnullnull, https://app.example.comnullnullnullyes
12null_not_in_listnullhttps://app.example.com———yes
13regex_subdomain_allowhttps://foo.app.example.comregex https://.*\.app\.example\.comhttps://foo.app.example.comhttps://foo.app.example.comhttps://foo.app.example.comyes
14regex_subdomain_denyhttps://evil.example.comregex https://.*\.app\.example\.com———yes
15regex_partial_vs_fullhttps://app.example.com.evil.comregex https://app\.example\.comhttps://app.example.com.evil.com—https://app.example.com.evil.comno
16regex_unanchoredhttps://app.example.com.evil.comregex app\.example\.comhttps://app.example.com.evil.com——no
17cred_exacthttps://app.example.comhttps://app.example.com + credentialshttps://app.example.comhttps://app.example.comhttps://app.example.comyes
18cred_starhttps://app.example.com* + credentials*https://app.example.comhttps://app.example.comno
19missing_origin(none)https://app.example.com——https://app.example.comno
20case_schemeHTTPS://app.example.comhttps://app.example.com——HTTPS://app.example.comno
21case_hosthttps://APP.example.comhttps://app.example.com——https://APP.example.comno

Appendix C. Real-world pattern probes

E/S/F = expressjs/cors / Starlette / Flask-CORS; Y = ACAO set to the probe origin (or *), N = absent. Pattern 15’s legitimate column uses https://a.test, because no real origin fully matches https://*. Pattern 16 is invalid and was not run.

PPattern (project-specific labels redacted)Anchored ^…$Legit probe E/S/FSuffix probe E/S/FUnrelated probe E/S/F
1^https?://(localhost(:\d+)?|<site>(\.<site>\.com)?|.*herokuapp\.com)$yesY/Y/YN/N/NN/N/N
2.*noY/Y/YY/Y/YY/Y/Y
3https?:\/\/.*\.<site>\.edu\.twnoY/Y/YY/N/YN/N/N
4http.*?://.*noY/Y/YY/Y/YY/Y/Y
5http://localhost:3000.*noY/Y/YY/Y/YN/N/N
6^(https?://(localhost|127\.0\.0\.1|tauri\.localhost)(:\d+)?|tauri://localhost)$yesY/Y/YN/N/NN/N/N
7https?://.*noY/Y/YY/Y/YY/Y/Y
8^https?://(localhost|127\.0\.0\.1):\d+$yesY/Y/YN/N/NN/N/N
9^http://(?:127\.0\.0\.1|localhost|\[::1\]):[1-9]\d{0,4}$yesY/Y/YN/N/NN/N/N
10^http://(localhost|127\.0\.0\.1):\d+$yesY/Y/YN/N/NN/N/N
11https://.*\.onrender\.comnoY/Y/YY/N/YN/N/N
12https?://(localhost|127\.0\.0\.1)(:\d+)?noY/Y/YY/N/YN/N/N
13^https?://(localhost|127\.0\.0\.1)(:\d+)?$yesY/Y/YN/N/NN/N/N
14http://localhost:(517\d|5555)noY/Y/YY/N/YN/N/N
15https://*noY/N/Y (https://a.test)—Y/N/Y
16*noinvalid regex (not run)——
17^https://.*\.vercel\.app$yesY/Y/YN/N/NN/N/N
18https://.*\.vercel\.appnoY/Y/YY/N/YN/N/N
19https://.*\.lovable\.app|http://localhost:\d+noY/Y/YY/N/YN/N/N
20https://.*\.usefleet.ainoY/Y/YY/N/YN/N/N
21^http://(127\.0\.0\.1|localhost):517\d$yesY/Y/YN/N/NN/N/N
22http://(localhost|127\.0\.0\.1)(:\d+)?noY/Y/YY/N/YN/N/N
23https?://(localhost|127\.0\.0\.1):\d+noY/Y/YY/N/YN/N/N
24(https://.*\.<site>\.me)|(http://127.0.0.1.*)|(https://.*\.github\.io)|(https://.*\.<site>\.cl)noY/Y/YY/Y/YN/N/N
25https://(<site>.*\.vercel\.app|([a-z0-9-]+\.)?<site>\.pages\.dev)|http://localhost(:\d+)?noY/Y/YY/N/YN/N/N
26https://.*\.netlify\.appnoY/Y/YY/N/YN/N/N
27https://.*\.example\.orgnoY/Y/YY/N/YN/N/N
28https://.*azurecontainerapps.ionoY/Y/YY/N/YN/N/N
29https://.*.officescripts.microsoftusercontent.comnoY/Y/YY/N/YN/N/N
30http://(localhost|127\.0\.0\.1):\d+noY/Y/YY/N/YN/N/N

References

  1. expressjs/cors, v2.8.6. https://github.com/expressjs/cors
  2. Starlette CORSMiddleware documentation. https://www.starlette.io/middleware/#corsmiddleware
  3. Flask-CORS documentation, v6.0. https://flask-cors.readthedocs.io/
  4. WHATWG Fetch Standard, CORS protocol. https://fetch.spec.whatwg.org/#http-cors-protocol
  5. W. M. McKeeman. Differential Testing for Software. Digital Technical Journal 10(1), 1998.