Skip to content
FunnelGuard

Fix guide by FunnelsGuard

CORS misconfigured with Access-Control-Allow-Origin *: how to fix

OPS-181Medium impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

By default, a browser stops a page on one site (say evil.example) from reading responses from another site (yourshop.com). CORS is the set of HTTP headers that lets you relax that rule on purpose. The key headers are Access-Control-Allow-Origin (who may read) and Access-Control-Allow-Credentials (whether cookies and login sessions are included).

The misconfiguration comes in two forms. First, Access-Control-Allow-Origin: * together with Access-Control-Allow-Credentials: true. Browsers refuse this combination, so your own cross-site requests fail. Second, and worse, code that copies whatever Origin the request sends into the response header while also allowing credentials. That one works, and it lets any website read logged-in data from your visitors.

Why it costs you leads or sales

There are two costs. The first is security: with a reflected origin plus credentials, a malicious page can make a logged-in customer's browser call your endpoints and read the answers, such as order history, addresses or account details. That risks data exposure and trust.

The second is breakage. If you send * with credentials, the browser blocks the response. Your checkout widget, embedded form, or cross-domain API call can fail silently with a console error, and visitors simply do not convert.

How a reflected-origin CORS bug leaks data
  1. Visitor logged inHas a session cookie for your site
  2. Opens other siteA page you do not control
  3. Script calls your APIBrowser attaches the cookie
  4. Server echoes OriginAllow-Origin copies the caller
  5. Data readPrivate response exposed

The leak happens in the browser of a visitor who is logged in to your site.

How to check if your site has it

Send a request with a fake Origin and look at the response headers. Use an endpoint that returns private or logged-in data, as well as your main API paths.

Test whether your server trusts any originbash
curl -s -I https://yourshop.com/api/account \
  -H 'Origin: https://evil.example' \
  -H 'Cookie: session=YOUR_TEST_SESSION' | grep -i '^access-control'

# Bad: the fake origin is echoed back with credentials
# access-control-allow-origin: https://evil.example
# access-control-allow-credentials: true

# Also check the null origin
curl -s -I https://yourshop.com/api/account -H 'Origin: null' | grep -i '^access-control'
Signs you have the problem
  • Response shows Access-Control-Allow-Origin: * on an endpoint that uses cookies
  • The Allow-Origin value changes to match any Origin you send
  • Access-Control-Allow-Origin: null is returned for a null origin
  • Console error: 'wildcard cannot be used when credentials mode is include'
  • A regex allows lookalike domains such as yourshop.com.evil.example

How to fix it

Replace the wildcard with an allowlist
  1. List the origins that truly need access

    Write down each exact origin (scheme, host, port), such as https://www.yourshop.com and https://checkout.yourshop.com.

  2. Match the Origin against that list

    Use exact string comparison. Avoid loose regex or 'ends with' checks, which let attacker domains through.

  3. Send the header only on a match

    If the origin is on the list, return it in Access-Control-Allow-Origin. If not, send no CORS headers.

  4. Add Vary: Origin

    This stops caches and CDNs serving one origin's response to another.

  5. Drop credentials where not needed

    Only send Access-Control-Allow-Credentials: true for endpoints that need cookies. Public endpoints can use * without credentials.

Where to set it
  1. Allowlist in application code (Node/Express example)

    Compare the Origin to a fixed array, set headers only on a match, and always add Vary: Origin. The popular cors package accepts an origin array and credentials: true.

nginx allowlist with Vary: Originnginx
map $http_origin $cors_origin {
    default "";
    "https://www.yourshop.com"      $http_origin;
    "https://checkout.yourshop.com" $http_origin;
}

server {
    location /api/ {
        add_header Vary Origin always;
        if ($cors_origin) {
            add_header Access-Control-Allow-Origin $cors_origin always;
            add_header Access-Control-Allow-Credentials true always;
        }
    }
}
CORS response headers

Before

  • Allow-Origin echoes any caller
  • Credentials allowed for everyone
  • No Vary header

After

  • Only listed origins get headers
  • Credentials only on endpoints that need them
  • Vary: Origin on responses

How to confirm it's fixed

Repeat the curl test with a fake origin. You should see no Access-Control-Allow-Origin header at all. Then test with each trusted origin and confirm the header matches it exactly. Finally, load your real pages and check the browser console and Network tab for CORS errors on legitimate calls.

Expected results after the fix
Origin sentExpected Allow-OriginCredentials header
https://www.yourshop.comhttps://www.yourshop.comtrue
https://evil.example(none)(none)
null(none)(none)
https://yourshop.com.evil.example(none)(none)

How to prevent it happening again

Keep CORS tight
  • Keep the allowlist in one place in code or config, under version control
  • Never copy the request Origin straight into the response
  • Do not allow null as an origin
  • Review CORS when adding a new subdomain, app or CDN
  • Include a CORS check in security reviews and penetration tests
  • Always send Vary: Origin when the value depends on the request

How FunnelGuard handles this

This issue is outside what FunnelGuard checks. FunnelGuard runs your customer journeys, such as forms, checkouts and tracking hits, on a schedule. It does not inspect your CORS response headers for security flaws. For this, use a web application security scanner or a penetration test, which probe your endpoints with crafted Origin headers. A CORS error that breaks a form or checkout step would show up as a failed journey, but finding the security flaw itself needs a security tool.

FunnelGuard has a Free plan with 1 site and 2 journeys, and paid plans come with a 3-day free trial.

Questions people ask

Why does Access-Control-Allow-Origin * not work with credentials?

Browsers block it on purpose. When a request includes cookies or other credentials, the response must name one specific origin, not *. The fix is to return the exact trusted origin and Access-Control-Allow-Credentials: true.

Is Access-Control-Allow-Origin * a security risk?

Not always. It is fine for public content that needs no login, such as open fonts or a public API. It is a risk when used on endpoints that return private data, or when paired with code that reflects any origin.

How do I test my site for CORS misconfiguration?

Use curl to send a request with an Origin: https://evil.example header and read the response headers. If your server echoes that origin back, especially with Access-Control-Allow-Credentials: true, it is misconfigured. Also test Origin: null.

What is the safe way to allow multiple origins in CORS?

Keep an allowlist of exact origins and compare the request Origin to it. If it matches, return that origin in the header. Otherwise send no CORS headers. Add Vary: Origin so caches stay correct.

Why is reflecting the Origin header dangerous?

It makes the server trust every website. With credentials allowed, a malicious page can make a logged-in visitor's browser call your site and read the response, exposing private data.

Can FunnelGuard detect CORS misconfiguration?

No. This is outside what FunnelGuard checks. Use a web application security scanner or a penetration test to find CORS flaws. FunnelGuard is built to run customer journeys and tracking checks.

Do I need CORS headers for my own pages?

No, not for same-origin requests. You only need CORS when a page on one origin (including a different subdomain or port) reads responses from another. If nothing cross-origin needs access, send no CORS headers.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.