Access-Control-Allow-Origin: Server's answer to cross-origin requests: which origins may read this response. The most-asked-about HTTP header on Stack Overflow. Access-Control-Allow-Origin decides which websites may read a response from your server in the browser. It is the core of CORS, and the header behind countless error messages on Stack Overflow. Browsers block JavaScript on one origin from reading responses from another, unless the server explicitly allows it. The value is either one origin, such as https://app.example.com, or * for any origin.
Frequently asked questions about Access-Control-Allow-Origin
What should you keep in mind with Access-Control-Allow-Origin?
Use * only for truly public data without cookies, such as a public JSON feed. For anything tied to a user, list the exact origins you trust. Remember that CORS protects users in browsers, not your server. Anyone can still call your API directly with curl. Authentication and permission checks remain your real security; CORS only decides which websites may use a visitor's browser to read the result.
What does an example of Access-Control-Allow-Origin look like?
Use when reviewing or setting HTTP response headers for a web app or API - security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS headers, caching headers (Cache-Control, ETag, Last-Modified, Vary) and cookies (Set-Cookie flags). Also use when a security scan reports missing headers.
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
'Expert-level browser automation, debugging, and performance analysis using Chrome DevTools MCP. Use for interacting with web pages, capturing screenshots, analyzing network traffic, and profiling performance.'