The scanner says the API reflects any Origin. Can a hostile page read the response? CORS misconfiguration as a DAST finding: Origin reflection, the null origin, allow-list regexes, subdomain and http origins, Vary and SameSite, and how the finding gets confirmed

DedSec Security Research ·

Here is a hypothetical. A dynamic scan of a web application and its JSON API returns three results from its CORS checks. The first, titled "CORS misconfiguration: wildcard origin with credentials" and rated high, is on /api/catalog: every response carries Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true. The second, titled "CORS: arbitrary origin reflected" and rated low, is on /api/account: the scanner sent Origin: https://evil.test, the response echoed it, and the status was 401, because the scan ran without a session. The third is /api/billing, where the scanner sent the same origin, got no Access-Control-Allow-Origin back, and reported it clean.

The high gets a ticket with a deadline. The low goes into the backlog. Nobody looks at the clean result. As in the earlier posts in this series, each call rests on the title and the rating rather than on what the scanner observed and what that observation can prove. A browser refuses to combine a wildcard with credentials, so the first finding is a configuration that grants nothing an attacker can read with the victim's cookies. The 401 on the second says the scanner had no session, not that a session would not be readable. And the third was tested with one hostile origin out of the many that a badly written allow-list will accept.

This post is for whoever is holding a CORS finding from a dynamic scan, or a clean result they are about to rely on. It covers what the browser actually enforces, which is reading and not sending; when a request is preflighted and why a "CORS finding" on a state-changing simple request is really a CSRF question; what the widely used Node.js cors package did with each of its origin options and ten Origin values; seven misconfigurations in mechanism; what a real browser did with sixteen cross-origin requests; what a shared cache did with and without Vary: Origin; the false positives and false negatives, including what SameSite cookie defaults change; how to confirm a finding, and why a server-side probe alone cannot; the fix; and the static-analysis view. It is the thirteenth post in a series about confirming DAST findings, after reflected XSS, SQL injection, OS command injection, Nuclei template matches, ffuf content discovery, path traversal, open redirect, SSRF through URL-fetch parameters, XXE, CRLF header injection, Host header injection and HTTP request smuggling. The security headers post has a short section, "CORS is not a hardening header", that states the Fetch standard's CORS check, the wildcard-and-credentials rule and the main allow-list mistakes; this post assumes it and goes further, into what each mistake looks like on the wire and in a browser.

Sources, and how each was checked. The measurements below were made on our test machine on 2 November 2026, on Ubuntu 24.04, inside a Linux network namespace with only a loopback interface, with every server and the browser running as a non-root user. We confirmed the isolation before the run: a lookup of the external name example.com failed, so every hostname in this post, example.com included, resolved only to the loopback addresses we mapped it to. The software was Node.js 22.22.2 with Express 4.21.2 and the cors package version 2.8.5 (which depends on vary 1.1.2), all three already installed on the machine and used as found; Python 3.12.3 (Ubuntu package 3.12.3-1ubuntu0.17), whose http.server we used for a hand-written reflecting handler and a page server and whose http.client sent the header probes; nginx 1.24.0 as a shared cache; and a real browser, Google Chrome for Testing 153.0.8010.12 running headless, driven by Playwright 1.64.0, both already on the machine. That Playwright release expects a later browser build than the one installed, so we launched the browser through an explicit executable path rather than installing the expected build. We installed nothing. The browser reached our servers over HTTPS with a self-signed certificate, which we told it to accept, and resolved names through a command-line mapping rather than DNS. We read the cors package's source and README on disk, and the behaviour described below as the package's is what we measured, cross-checked against that source. The WHATWG Fetch standard, MDN, the OWASP Web Security Testing Guide and the cookie specifications are cited by name and described in our own words, because we had no copy on the machine to quote from; anything we attribute to them and did not measure is marked as cited. We did not test Firefox, Safari or any other WebKit browser, any Chrome profile with third-party cookies blocked, any CDN, or any framework other than Express. The opening scenario is hypothetical, and no number in this post measures any scanner, ours included.

What the browser enforces, and what it does not

Without CORS, the same-origin policy lets a page on one origin send many kinds of request to another origin, and stops it reading the response. CORS is a way for the server to relax the second half. It never had anything to say about the first. The WHATWG Fetch standard defines the check a browser runs on a cross-origin response before handing it to the script that asked for it. In outline:

"Credentials" in Fetch means cookies, HTTP authentication entries the browser holds, and TLS client certificates. Credentials mode "include" is what a script asks for with fetch(url, {credentials: "include"}) or xhr.withCredentials = true. The check looks at the mode, not at whether any cookie was actually attached: a credentialed request against a wildcard fails even when the browser had no cookie to send (cited from the Fetch standard; our wildcard test had a cookie attached).

When the check fails, the script gets a network error. For a request that needed no preflight, the request has still been sent and the server has still answered. That is the most important fact for triage, and we measured it below: our server executed a state-changing POST whose response the attacking page could not read.

Not every cross-origin request is sent straight away. Fetch sends a preflight, an OPTIONS request carrying Access-Control-Request-Method and Access-Control-Request-Headers, first, unless the request is what it calls CORS-safelisted: a GET, HEAD or POST, with only safelisted headers, and a Content-Type, if any, of application/x-www-form-urlencoded, multipart/form-data or text/plain (cited from the Fetch standard; the two cases we measured are below). The preflight response must itself pass the CORS check and must allow the method and headers; if it does not, the real request is never sent.

So there are two different questions behind any "CORS finding", and they have different answers:

The claim a finding must support

CWE-942 (permissive cross-domain policy with untrusted domains) is the usual classification, sometimes alongside CWE-346 (origin validation error). Underneath either, an exploitable CORS finding is a conjunction of four things, and a scanner usually sees one or two:

  1. The server grants a hostile origin that a browser will really produce. Access-Control-Allow-Origin matches that origin exactly, and for a credentialed read Access-Control-Allow-Credentials: true is also present. "A browser will produce" matters: an attacker cannot send an arbitrary Origin from a victim's browser; Origin is on the Fetch standard's list of forbidden request headers (cited), so it is set by the browser from the page's real origin, or as null.
  2. The victim's browser attaches the credential on that cross-origin request. A session cookie with the right SameSite attribute, in a browser that sends it, or HTTP authentication or a client certificate the browser holds. A bearer token kept in the application's own JavaScript is not attached by the browser.
  3. The response contains something worth reading under those credentials: personal data, API keys, a CSRF token, anything that enables a further step.
  4. For a non-simple method, the preflight passes as well.

A finding built on the first half of point 1 alone, a reflected Origin, is a common false positive in this class. A clean result built on one probe origin is a common false negative.

What the cors package does with each origin option, measured

The cors package for Express takes an origin option in five forms, documented in its README: true to reflect the request's Origin, a string, a RegExp, an array of strings and RegExps, or a function. credentials: true adds Access-Control-Allow-Credentials: true. The default, with no options, is origin: "*". We ran sixteen configurations, one per port, each in front of the same handler that returned a JSON body containing a marker string standing in for account data, and sent each one ten Origin values with Python's http.client, as GET and as an OPTIONS preflight. The legitimate front end was https://app.example.com. The ten values were:

Which non-legitimate values each configuration granted on GET, meaning it put that value in Access-Control-Allow-Origin:

Our hand-written Python handler, which copied the Origin header into Access-Control-Allow-Origin and added Access-Control-Allow-Credentials: true, reflected all nine values that carried an Origin, null included, never sent Vary, and with no Origin sent neither header. On preflight it reflected the requested headers as well.

Three results cut across the configurations. First, in every configuration, every Origin value got the full response body with a 200, except the 500s from the Error-callback form. The middleware decides which headers to add. It does not decide whether the handler runs. CORS is not access control. Second, nine of the sixteen configurations refused https://evil.test and still granted at least one other value an attacker can produce: null, a subdomain of the attacker's own domain, a registrable lookalike, an http origin, or a subdomain of yours. A probe with one arbitrary origin reports all nine as clean. Third, on preflight the package answered rejected origins in the array form with a 204 carrying Access-Control-Allow-Credentials: true, Access-Control-Allow-Methods and an Access-Control-Allow-Headers copied from the request, and no Access-Control-Allow-Origin. The package reflects requested headers by default unless allowedHeaders is set, which its README documents. Under the Fetch standard's check, a browser rejects that preflight, because the origin header is missing (cited; we did not drive a browser at the array form's preflight); a scanner that keys on the presence of the credentials or methods header does not.

The misconfigurations that matter, in mechanism

Arbitrary Origin reflection with credentials. The server copies whatever Origin arrives into Access-Control-Allow-Origin and adds Access-Control-Allow-Credentials: true. Every web page the victim visits can read any response for which the victim's browser attaches credentials on a request from that page. In our Chromium run, from a cross-site page, that meant requests authenticated by the SameSite=None cookie; from a same-site page, every cookie. It often starts as a workaround for the wildcard-with-credentials rule, and origin: true, credentials: true is that workaround as a one-line configuration. Our browser read the account data from a page on https://evil.test.

null in the allow-list. A browser sends Origin: null from contexts whose origin is opaque. MDN's page on the Origin header lists, among others, documents with non-hierarchical schemes such as data:, sandboxed iframes without allow-same-origin, and requests that went through a cross-origin redirect; whether a file: page sends null varies by browser (cited, not tested). Any attacker can create the sandboxed iframe case on their own page, which is the one we measured: a sandbox="allow-scripts" iframe on https://evil.test sent Origin: null, and against an allow-list containing "null" it read the account data. One way null ends up allow-listed is that a developer saw it in the logs while testing from a local file and added it.

Unanchored or badly escaped regexes. A regex that is not anchored at the start accepts any prefix; one not anchored at the end accepts any suffix; an unescaped dot accepts any character. /example\.com/ matched https://app.example.com.evil.test, which is a host under the attacker's own domain, and https://evilexample.com, which they can register. /^https:\/\/app.example.com$/ matched https://appxexample.com. Each is a test that looks like a parsed comparison and is not one.

Suffix and prefix string matching. endsWith("example.com") is the README regex without the regex: it granted evilexample.com. startsWith("https://app.example.com") granted https://app.example.com.evil.test and any port. includes granted everything with the substring in it. This is the same class of bug the SAST false-positive post describes from the other side, a sink matched as a bare substring: a string test standing in for structure.

Trusting every subdomain. A pattern that accepts every subdomain hands read access to whoever controls any one of them: through a dangling DNS record pointed at a resource someone else can now claim, through an XSS on a marketing site, or through a forgotten staging host. This one is stronger than the cross-site cases for a reason that has nothing to do with CORS: a subdomain is the same site, so SameSite cookies, Lax and Strict included, are sent. We measured that below. A cross-site attacker in Chromium got only the SameSite=None cookie; a page on https://forgotten.example.com got all four.

http origins granted by an https site. If the allow-list accepts http:// origins, anyone who can inject into an unencrypted page under that name, a network attacker on the victim's Wi-Fi being the classic case, gets the grant. Our "all subdomains" regex allowed it, and a page on http://forgotten.example.com read the account data. In Chromium, that page was treated as cross-site for cookies even though the host was a subdomain: only the SameSite=None cookie was attached. Chrome calls this schemeful same-site, and the revised cookie specification known as RFC 6265bis takes the scheme into account when deciding whether a request is same-site (cited); we observed the behaviour in Chromium and did not test other browsers.

Missing Vary: Origin. If the value of Access-Control-Allow-Origin depends on the request's Origin, a cache that does not know that will store one origin's answer and serve it to others. MDN's guidance (cited) is to include Origin in Vary whenever the server's CORS response depends on the requesting origin. The measured consequence is mostly breakage rather than theft, described below, and the cors package's function form produces a less obvious version of it.

What the browser did, measured

We logged a test user in by navigating the browser to https://api.example.com/login, which set four cookies, all Secure and HttpOnly: one each with SameSite=None, Lax and Strict, and one with no SameSite attribute. Chromium's cookie store reported that last one as Lax, which is its default for a cookie with no attribute. We then loaded an otherwise empty page on each attacking origin and ran fetch from it. The API echoed back which cookies it received, so the readable responses show what was attached, and a server-side log records what arrived even when the page could not read it.

The text/plain POST and the JSON POST, side by side, are the whole CSRF point. The endpoint with no CORS policy at all executed a cross-site action because the request was safelisted. The JSON endpoint was protected by the preflight, not by anything the server did on purpose, and a reflecting policy removed that protection. Our lab handler did not parse the body at all, so in what we measured the preflight was the only thing in the way. In an Express application the usual JSON parser adds the other half: express.json() is body-parser's JSON parser, and in body-parser 1.20.3, read from its source on our machine and not exercised in the lab, the type option defaults to application/json and a request with any other Content-Type is passed on unparsed. So an endpoint that reads its input through that parser gets nothing from a text/plain body, and an attacker who needs the JSON to be parsed has to send the Content-Type that triggers the preflight. Neither half was chosen as a CSRF defence.

Vary: Origin and a shared cache, measured

We put nginx's proxy cache in front of three backends, set it to cache 200 responses for a minute, and sent three requests for the same URL with different Origin values. Our Python handler marked its responses publicly cacheable; the Express responses carried no cache headers, so caching them came from our nginx configuration alone.

In each failing case, the legitimate front end's next read would fail the browser's check until the entry expired. We read that off the headers; we did not drive a browser through the cache. Any visitor from any non-allowed origin, or a scanner, can cause it with one request. In the matrix, that configuration's response to a request with no Origin also carried no CORS headers and no Vary, so a request with no Origin at all would very likely break the entry in the same way. We infer that and did not measure it: in our cache test the no-Origin request came last and was served the broken entry, not the cause of it. The reverse direction, a hostile origin receiving a cached grant for the legitimate one, does not help an attacker on its own, because the cached header names the legitimate origin and the browser compares it with the attacker's. James Kettle's 2016 PortSwigger research on CORS misconfigurations describes how a missing Vary: Origin can be combined with other bugs, such as a request header reflected without encoding, to poison a browser's or a server's cache (cited, not tested). Separately, a shared cache that stores a response carrying one user's account data and serves it to another is a bug before CORS enters into it; our Python handler only did so because we told it to mark the response public.

What scanners flag that is not exploitable

What scanners miss

Confirming a finding by hand

The procedure below is general practice. Use a test account, and send reads only to your own logging endpoint.

  1. Probe the variants from the command line. For each value in the list above, built from the target's real domain, send the request with and without a valid session cookie, for example curl -s -i -H "Origin: https://evilexample.com" -H "Cookie: session=..." https://api.example.com/me. Record status, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Vary, and whether the body has sensitive content. Include null and the no-Origin case.
  2. Check both headers together. A matching Access-Control-Allow-Origin without Access-Control-Allow-Credentials: true grants only non-credentialed reads. * with credentials grants nothing credentialed.
  3. Read the authenticated body. Decide what an attacker gets: personal data, tokens, CSRF tokens, keys. If it is nothing, the finding is a policy smell on that endpoint.
  4. Identify the credential. Cookie, which SameSite value, and which Domain; an Authorization header from application storage; browser-managed HTTP auth; a client certificate. A bearer token from application storage usually ends the finding.
  5. Probe the preflight for non-simple methods. curl -s -i -X OPTIONS -H "Origin: ..." -H "Access-Control-Request-Method: PUT" -H "Access-Control-Request-Headers: content-type" .... If it passes, the finding covers actions as well as reads.
  6. Prove it in a real browser. This is the step a server-side probe cannot replace, because the probe cannot show which cookies a browser attaches or whether it accepts the headers. Host a page on an origin that matches the accepted variant, log in as the test user in the same browser, and from the page run fetch("https://api.example.com/me", {credentials: "include"}).then(r => r.text()), showing or posting the result to your own endpoint. For null, put the script in a sandbox="allow-scripts" iframe. For a lookalike you do not own, a test browser can map the name to your own server: Chromium's --host-resolver-rules flag is what we used. That proves the browser accepts the grant for that origin string; whether an attacker can register or take over the name is a separate check. Repeat in the browsers your users actually run, because cookie behaviour differs. We ran headless Chromium only.
  7. Check caching. Send two requests for the same URL with different Origins through whatever cache sits in front, and see whether the second gets the first's header.
  8. Keep the evidence: the exact requests and response headers, the browser and version, the page's origin, and what the page read.

The fix

All of this is general practice except where it says it was measured.

The static side

Static analysis models a reflecting policy as taint: the source is the request's Origin header, req.headers.origin or request.headers["Origin"], and the sink is a write to Access-Control-Allow-Origin, either directly or through configuration such as origin: true. The interesting part is the sanitiser. A rule that credits any if (allowed.test(origin)) or origin.endsWith(...) before the sink as validation is crediting a sanitiser that does not sanitise, the error the SAST false-positive post describes; a precise rule has to look at the regex itself, its anchors and escaped dots, or the string method. Configuration-level patterns such as credentials: true with a RegExp or function origin, or an allow-list containing "null" or an http:// entry, are findable from source. What is not findable from source is which subdomains exist, which cookies the session uses in production, and what a cache in front does. Those were exactly the parts of the confirmation that needed the deployment.

A triage checklist for a DAST CORS finding

  1. Which origin was granted, and could a browser produce it? An arbitrary domain, null, a lookalike, an http origin, a subdomain, or your own front end.
  2. Is Access-Control-Allow-Credentials: true present with an exact-match grant? * with credentials grants no credentialed read; it still allows reads without cookies.
  3. What does the authenticated response contain?
  4. What credential does the endpoint use, and will the browser send it cross-site or same-site? SameSite value, browser, Authorization header.
  5. Does the preflight pass? If so, the finding includes actions.
  6. Is a state-changing simple request really a CSRF finding? Treat it as one.
  7. Re-probe with the full variant list around the real domain, not one arbitrary origin.
  8. Confirm in a real browser with a PoC page on a matching origin, in the browsers your users use.
  9. Check Vary: Origin and caching.
  10. Retest with the variant that raised the finding, plus the others, with a session, and confirm the scan reached the handler and not a login redirect. The scan-passed post covers how that goes wrong.

The hypothetical findings, resolved

Back to the three hypothetical findings.

In the scenario, the /api/catalog "wildcard with credentials" was the cors default with credentials: true added. A PoC page making a credentialed request failed with a network error, and a non-credentialed request read a catalogue that was public anyway. It was re-rated as informational and fixed by removing the credentials option, so that the next person did not switch it to reflection.

In the scenario, the /api/account reflection was rated low because the scanner had no session. With a test user's session, the same request returned the user's profile and an API key, with Access-Control-Allow-Credentials: true. The session cookie was SameSite=None because the product was embedded in a partner's site. A PoC page on a tester-controlled domain read the profile in Chromium. It was re-rated high and fixed with an exact list of the two front ends and the partner's origin, with Vary: Origin.

In the scenario, the /api/billing clean result was a false negative. The policy was an endsWith test against the company domain. https://evilexample.com was granted, and the billing endpoint also accepted JSON PUTs through a passing preflight. It was fixed with the same exact list, and the retest sent the full variant list with a session.

Where AppSecD fits

AppSecD's dynamic and API testing runs Nuclei, Dalfox, SQLMap, Commix, Katana, Arjun, FFuf and Interactsh for out-of-band detection, plus 150+ native checks and API discovery across 50+ web frameworks. In its lifecycle this is the runtime stage: DAST and API testing run against the deployed application, because code review cannot see a misconfigured production header, an exposed API route or an injection that only appears once the application is assembled and running. Its static analysis includes dataflow taint analysis that traces source to sink across functions. Its AI layer triages false positives and assembles attack chains across findings, showing how separately unremarkable issues combine. Its findings are deduplicated across scans and tracked through new, reopened and fixed states, and they need maker-checker approval to close, so a finding cannot be closed unilaterally.

That is the whole claim, and data/products.ts, the single source of truth for what these products do, does not mention CORS, Origin, cross-origin policy or cookies at all. So this post does not claim that AppSecD has a dedicated CORS check, which Origin values or variants it sends, whether it builds variants from the target's domain, whether it sends null or tests preflights, whether it scans with a session or compares authenticated responses, whether it distinguishes a wildcard with credentials from a reflecting grant, whether it checks Vary or caching, whether it runs anything in a browser, how it rates the severity of such a finding, whether its AI triage or attack-chain assembly treats CORS findings in any particular way, whether its static rules model Origin as a source or judge allow-list regexes, or how accurate any such detection would be. The measurements, the confirmation procedure, the fixes and the checklist above are general practice, not a description of how AppSecD works internally, and they apply to any scanner's output, ours included. The scenario in this post is hypothetical and does not describe any AppSecD deployment, user or finding.

More about AppSecD · All posts