Networking & Protocols (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Cross-Origin Resource Sharing (CORS): Simple requests vs Preflight `OPTIONS`.
senior LevelMost AskedSecurity & Auth
In Simple Words: A browser security mechanism enforcing the Same-Origin Policy (Protocol, Domain, Port):
- Simple Requests (GET/POST with standard headers): Browser sends request directly, including
Originheader. Server responds withAccess-Control-Allow-Origin. - Preflight Requests (
OPTIONS): Triggered if the request uses custom headers (e.g.Authorization,Content-Type: application/json) or mutating methods (PUT,DELETE):- Browser automatically fires a preflight
OPTIONSrequest first: "Are you willing to accept a PUT request with an Authorization header from example.com?" - The actual data request executes only after the server approves the preflight headers.
- Browser automatically fires a preflight