What is CORS, why does the browser block requests, and how do you fix it correctly?
Reviewed by Gurusankar M.
β‘ Short Answer
CORS is a browser security mechanism: by default a page can't read responses from a different origin unless the server sends Access-Control-Allow-Origin (and friends). The browser may send a preflight OPTIONS first. Fix it on the SERVER by allowing the specific origin/methods/headers β not with a wildcard for credentialed requests.
βCoffee Chat Question
Concept Made Simple
βWhat is CORS, why does the browser block requests, and how do you fix it correctly?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
CORS works in Postman but fails in the browser β why?
CORS is enforced ONLY by browsers β Postman/curl ignore it. The request itself succeeds; the browser blocks the page from READING the response because the server didn't return the right Access-Control-Allow-Origin. The fix is server-side CORS config, not client code.
πReal World
CORS errors are a daily frontendβAPI friction; the fix is always configuring allowed origins/methods/headers on the server (or gateway), and never '*' when cookies/credentials are involved.
π―Interviewer's Expectation
Keywords they're listening for:
β οΈCommon Mistakes
- βTrying to fix CORS on the client
- βAllow-Origin '*' with credentials
- βForgetting to allow custom headers/methods
β Best Practices
- βConfigure CORS server/gateway-side
- βAllow specific origins for credentialed requests
- βLimit allowed methods/headers to what's needed
πFollow-up Questions
- 1What makes a request 'simple' vs 'preflighted'?
- 2Why can't you use '*' with credentials: include?
- 3Where do you configure CORS β app or gateway?
π§©Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Auth (REST APIs) Interview question: "What is CORS, why does the browser block requests, and how do you fix it correctly?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.