Home
← All questions

CORS — deep dive | Web Fundamentals

HardPremiumWeb Fundamentals

Asked at Google · Stripe · Amazon

Web Fundamentals interview practice: Explain Cross-Origin Resource Sharing, preflight requests, and common misconfigurations.

Answer

Same-Origin Policy blocks JS from reading cross-origin responses. CORS is a server-controlled relaxation via HTTP headers.

Simple requests (GET/POST with safelisted headers) go directly; browser checks Access-Control-Allow-Origin on response.

Preflight (OPTIONS) happens for "non-simple" requests (custom headers, PUT/DELETE, Content-Type: application/json). Browser sends Access-Control-Request-Method/Headers; server must respond with matching allow headers before the real request.

Key headers:

  • Access-Control-Allow-Origin — specific origin or * (no credentials with *)
  • Access-Control-Allow-Credentials: true + explicit origin (required for cookies)
  • Access-Control-Allow-Methods, Access-Control-Allow-Headers
  • Access-Control-Max-Age — cache preflight
Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium