Define the Same-Origin Policy (SOP) and explain its primary significance in web security.
Which of the following pairs represents a 'same origin' scenario?
Which of the following pairs represents a 'cross-origin' scenario?
Explain why Cross-Origin Resource Sharing (CORS) was introduced and how it works as a security mechanism to relax the Same-Origin Policy.
Describe the role of preflight requests in CORS. What HTTP method is typically used for a preflight request, and what information does it convey?
Explain the purpose of the Access-Control-Allow-Origin
header and provide an example value that would allow a frontend application running on http://localhost:3000
to access an API.
Explain the purpose of the Access-Control-Allow-Methods
header and provide an example value to permit GET
and POST
requests from a cross-origin frontend.
Explain the purpose of the Access-Control-Allow-Headers
header and provide an example value to allow custom headers X-Auth-Token
and Content-Type
.
Explain the purpose of the Access-Control-Expose-Headers
header and provide an example value to make X-Custom-Header
accessible to a frontend script.
Explain the purpose of the Access-Control-Max-Age
header and provide an example value to cache preflight results for 10 minutes.
Explain the purpose of the Vary
header in the context of CORS and provide an example value.
Explain why Access-Control-Allow-Origin: *
should generally be avoided in production environments and what security risks it poses.
Describe the best practice for setting the Access-Control-Allow-Origin
header in production environments, especially when dealing with multiple legitimate origins.