CORS config review
Goal
Let the intended web front ends call the API and nobody else's pages.
A good fix names exact origins, and the user understands that CORS is a browser rule, not authentication.
When to use
- The API sets
Access-Control-Allow-Origin. - The browser shows a CORS error during development or after a deploy.
- A review sees
*or origin reflection. - For other response headers, use
use_skillwithsecurity-headers.
Steps
- Find CORS code and proxy config with
rgforAccess-Control,cors(,CORS_,allowedOriginsandadd_headerin nginx files. Read each withread_file. - List which origins should be allowed: the production site, staging, local development. Ask the user if unclear.
- Check how the allowed origin is chosen. Flag:
*, an origin copied from the request without checking a list, regex without anchors, andendsWithorincludeschecks. - Check credentials.
Access-Control-Allow-Credentials: truemust pair with an exact origin, never a wildcard. Confirm whether cookies are even used. - Check
nullorigin acceptance, which sandboxed frames and local files can send. - Check allowed methods and headers: only those the front end needs. Check
Access-Control-Max-Ageis reasonable. - Check the response adds
Vary: Originwhen the value changes per request so caches do not serve one origin's answer to another. - Check preflight handling:
OPTIONSreturns the headers without requiring authentication and without running business logic. - Check what an allowed origin can actually read, and whether sensitive endpoints rely on network location or cookies alone.
- To reproduce an error, open the page with
browser_navigateand readbrowser_console, or send a request withrun_commandandcurl -i -H "Origin: ..."to see the headers. - Edit the config with
edit_fileto a fixed allow list, with separate lists per environment. - Re-test with an allowed origin, a disallowed origin and a preflight.
Gotchas
- CORS does not stop requests reaching the server. It only controls whether the browser lets a page read the response, so it is not a replacement for authorisation.
- Reflecting any
Originwith credentials allowed lets any site read a logged-in user's data. - A regex like
example.comunanchored also matchesexample.com.evil.net. - A browser error often hides a server failure: a 500 or a redirect without CORS headers reports as a CORS error.
- Developers add
*to fix an error and ship it. Keep local origins in development config only. - Subdomain wildcards trust every subdomain, including forgotten ones that can be taken over.
Output
- The current policy in plain words and the issues found, ranked.
- The corrected configuration.
- Test requests used and their headers.
