Skip to content

Instantly share code, notes, and snippets.

@DusanMadar
Last active July 11, 2022 19:15
Show Gist options
  • Save DusanMadar/6560b872385abb642e9c1d2b969d8e87 to your computer and use it in GitHub Desktop.
Save DusanMadar/6560b872385abb642e9c1d2b969d8e87 to your computer and use it in GitHub Desktop.
tl;dr CORS and Origin header

A brief summary of CORS and the Origin header

Latest revision: 2022-07-11.

This simple gist sheds a bit of light on CORS and indicating an HTTP request origin. Should be easy to trick the server by setting Origin header, right? Not really.

tl;dr

CORS is a browser mechanism build around the forbidden Origin request header. That means the browser/user agent is in charge of telling the server where the request originates from. Setting the header manually/with code has no effect.

Cross-origin resource sharing (CORS)

An HTTP-header based mechanism that allows a server to indicate any origins other than its own from which a browser should permit loading resources.

(source: Cross-Origin Resource Sharing (CORS))

A browser mechanism which enables controlled access to resources located outside of a given domain.

(source: Cross-origin resource sharing)

Headers

The Origin request header indicates the origin (scheme, hostname, and port) that caused the request.

(source: Origin)

The Access-Control-Allow-Origin response header indicates whether the response can be shared with requesting code from the given origin.

(source Access-Control-Allow-Origin)

A forbidden header name is the name of any HTTP header that cannot be modified programmatically; specifically, an HTTP request header name (in contrast with a Forbidden response header name). Modifying such headers is forbidden because the user agent retains full control over them.

(source: Forbidden header name)

Aditional resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment