Networking & Protocols (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is CORS (Cross-Origin Resource Sharing) and the Preflight Request?
junior LevelMost AskedSecurity & Auth
In Simple Words: A browser security mechanism enforcing the Same-Origin Policy:
- An origin is defined by
Protocol + Domain + Port. - If a frontend on
https://myapp.commakes an API call tohttps://api.com: - Preflight Request: The browser automatically sends an HTTP
OPTIONSrequest first:- Headers:
Origin: https://myapp.com,Access-Control-Request-Method: POST. - The server must respond with
Access-Control-Allow-Origin: https://myapp.com(or*). - If approved, the browser sends the actual
POSTrequest; if rejected, the browser blocks the response.
- Headers: