Skip to content

CORS Misconfigurations: Origin & Credentials

Understand CORS security risks: reflected Origin headers with credentials, null origin trust, and how to build a strict server-side origin allowlist.

By BugSnaps Security Research · 1 min read · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

Cross-Origin Resource Sharing (CORS) lets a server tell browsers which external web origins are permitted to read HTTP responses across origins. Because browsers enforce the Same-Origin Policy by default, a misconfigured CORS policy can weaken browser isolation and allow an untrusted website to read authenticated API responses from a signed-in visitor's session.

Why reflected Origin headers with credentials are dangerous

Browsers forbid combining a wildcard `Access-Control-Allow-Origin: *` header with `Access-Control-Allow-Credentials: true`. To make cross-subdomain or local development requests work quickly, developers sometimes configure middleware to copy whatever value arrives in the request's `Origin` header into `Access-Control-Allow-Origin` alongside `Access-Control-Allow-Credentials: true`:

  • Arbitrary origin reflection: if an API echoes `Origin: https://attacker.example` with `Access-Control-Allow-Credentials: true` (and the session cookie uses `SameSite=None`), a script on the attacker's page can fetch the user's private profile or API tokens.
  • Trusting `Origin: null`: sandboxed `<iframe>` elements and local `file:` contexts send `Origin: null`. Allowlisting `null` lets any hostile site use a sandboxed iframe to read credentialed responses.
  • Unanchored regex or prefix matching: checking `origin.includes('example.com')` or `origin.startsWith('https://example.com')` inadvertently approves attacker domains such as `https://example.com.attacker.test` or `https://notexample.com`.
  • Wildcard origins on private intranet APIs: even without credentials, setting `Access-Control-Allow-Origin: *` on an internal network service allows external web pages visited by an employee's browser to read internal responses.

How to implement a strict CORS allowlist

Store permitted origins as an exact set of full origin strings (for example, `https://app.example.com`). Parse and compare the incoming `Origin` header for an exact match against that set before emitting `Access-Control-Allow-Origin`, omit CORS headers completely when the origin is not in the allowlist, and always include `Vary: Origin` so CDN or browser caches never serve one origin's CORS headers to another.

MyPentest checks discovered web and API routes for unsafe Origin reflection, null-origin trust, and credentialed CORS misconfigurations.

Run a vulnerability scan on your website.

Verify your domain and use MyPentest to check for supported web and API weaknesses. Review findings and coverage; a clean scan does not rule out every CVE.