Interview Prep/Networking/TLS, HTTP & Application Layer

The browser console shows a CORS error when your frontend calls your API. What is it and how do you fix it?

BeginnerScenarioTLS, HTTP & Application Layer
Answer

Situation read → CORS is enforced by the browser, not the network; the API must say which origins may read the response.

What I'd do →

  1. Check the error: has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header
  2. Inspect the preflight: curl -i -X OPTIONS https://api.example.com/v1/items -H 'Origin: https://app.example.com' -H 'Access-Control-Request-Method: POST'
  3. Return Access-Control-Allow-Origin: https://app.example.com, allowed methods and headers
  4. Make sure the OPTIONS request is not blocked by auth or the gateway

Why → The server opts in to cross-origin reads with headers; a wildcard with credentials is rejected by browsers.

Interview tip → Say CORS is not a security control for the API itself.

All Networking questions Roadmap: Networking for DevOps

More on TLS, HTTP & Application Layer