CORS Header Builder and Preflight Explainer
Find out why a fetch is blocked by CORS: model your server policy, run a sample request through the browser's checks and get a fixed config.
Працює у вашому браузері. Ваші файли ніколи не залишають пристрій. Дізнатися, як це перевірити
…
Як користуватися
- 1Describe your policy
Enter allowed origins, methods, headers, credentials and max-age.
- 2Describe the request
Set origin, URL, method, headers, Content-Type and credentials.
- 3Read the steps
See whether a preflight happens and which check fails.
- 4Apply the fix
Press Fix the policy for this request if something is blocked.
- 5Export config
Pick your server or platform in the Server config tab and copy it.
- 6Look up errors
Use the Common errors tab to decode a console message.
Про цей інструмент
Cross-Origin Resource Sharing is the set of response headers that lets a page on one origin read data from an API on another. The rules live in the browser, not on the server, which is why a request that works perfectly in curl or Postman can fail in a web app with a red console message. Before many requests the browser first sends an OPTIONS preflight asking whether the real request is allowed, and it then checks the answer against a precise list of conditions: the allowed origin, credentials, methods and request headers. A missing Vary header, a wildcard origin combined with cookies, an Authorization header not listed, or an error page without CORS headers each produce a different message. This tool lets you describe your server policy, describe the request your front end makes, and watch each check pass or fail with the message Chrome would print.
Server policy
List allowed origins one per line. Exact origins such as https://app.example.com are matched exactly; a pattern such as https://*.example.org matches any subdomain; * allows every origin. Toggle the methods you accept, list allowed and exposed headers, decide whether credentials (cookies and HTTP authentication) are allowed, whether Vary: Origin is sent, and set Access-Control-Max-Age. Policy warnings point out combinations that never work or are risky, such as * with credentials, allowing the null origin, plain http origins and a max-age above Chrome's two-hour cap.
Preflight simulator
Enter the page origin, the API URL, the method, the request header names your code sets, the Content-Type and whether fetch uses credentials: 'include'. The simulator decides whether a preflight is needed and explains why, for example because PUT is not a simple method or application/json is not one of the three simple content types. It shows the OPTIONS request the browser sends, the response your policy produces, and each check in order: origin, credentials, method, each non-safelisted header, then the actual response. Response headers you want to read are compared with the seven always-readable ones and your expose list. When something fails, Fix the policy for this request adds exactly what is missing.
Server config
The same policy is written for Express with the cors package, plain Express middleware, Nginx with a map of allowed origins, Apache with SetEnvIf, Netlify or Cloudflare Pages _headers, vercel.json, Cloudflare Workers, AWS Lambda and Google Cloud Functions or Firebase. Dynamic platforms echo the allowed origin back; static header files can hold only one fixed origin, and the output says so.
Common errors
A reference tab lists the console messages developers meet most often, from No Access-Control-Allow-Origin header to It does not have HTTP ok status and Redirect is not allowed for a preflight request, each with its usual cause and fix.
Limits
The simulator follows the Fetch Standard rules for the cases it models; it does not send real requests, so it cannot see a proxy, CDN or framework that rewrites your headers. Private Network Access preflights and request bodies that are streams are not modelled. CORS is not an access-control system for your API: it only decides what browsers let pages read, so keep authentication on the server.
Приклад із розв'язанням
A front end on https://app.example.com sends PUT to https://api.example.com/v1/orders/42 with Authorization and X-Trace-Id headers, a JSON body and cookies. The policy allows four methods and the headers Content-Type and Authorization. The simulator shows a preflight with Access-Control-Request-Headers: authorization,content-type,x-trace-id; the origin, credentials and method checks pass, then the request is blocked because x-trace-id is not allowed. Fix the policy adds X-Trace-Id to the allowed headers and X-RateLimit-Remaining to the exposed ones. The run then succeeds in 7 steps, the 600 second max-age note included, and the Nginx tab gives a map block with three allowed origins.
Коротко
- Категорія: Розробка та дані
- Працює в браузері, без реєстрації й завантаження.
- Введені вами дані залишаються на пристрої.
- Доступно англійською.
- Вміст востаннє перевірено:
- Офіційне джерело: WHATWG Fetch Standard, CORS protocol
Поширені запитання
Why does my request work in Postman but not in the browser?
CORS is enforced only by browsers. Postman, curl and servers do not check these headers, so a missing header only shows up in a web page.
When does the browser send a preflight?
When the method is not GET, HEAD or POST, when your code sets a header outside the safelist, or when Content-Type is anything other than form-urlencoded, multipart form data or text/plain.
Can I use * with cookies?
No. With credentials the server must echo the exact origin and send Access-Control-Allow-Credentials: true; browsers reject * in that case.
Why can't JavaScript read a header I can see in DevTools?
Only seven response headers are readable by default. List others in Access-Control-Expose-Headers.
Why send Vary: Origin?
When the allowed origin depends on the request, caches must store one answer per origin. Without Vary, a CDN can serve one site's CORS answer to another.
Does the tool contact my API?
No. It models the browser rules locally and never sends a request.
