- When browsers must internally set an origin to a value that’ll getthat gets serialized as
null - When browsers must send the Origin header
When browsers must set origin to a value that’ll getthat gets serialized as null
In other words, everywhere the HTML spec says opaque origin, you can translate thatit to null.
The Fetch spec requires browsers to set the origin to a “globally unique identifier” (which basically meansessentially the same thing as “opaque origin”, which basically means null…) in one case:
- For
blob:URLs - For
file:URLs - For anyany other URLs whose scheme is not one of
http,https,ftp,ws,wss, orgopher.
Browsers send the Origin header for WebSocket requests and for cross-origin requests initiatedinitiated by a fetch() or XHR call, or by an ajax method from a JavaScript library (axios, jQuery, etc.) — but not for normal page navigations (that is, when you open a web page directly in a browser), and not (normally) for resources embedded in a web page (for example, not for CSS stylesheets, scripts, or images).
But that description isthat’s a simplification. There are cases other than WebSocket requests and cross-origin XHR/fetch/ajax calls when browsers send the Origin header, and cases when browsers send the Origin header for embedded resources. SoSo what follows below is the longer answer.
In terms of the spec requirements: The spec requires the Origin header to always be sent onlyfor WebSocket requests and for any request which the Fetch spec defines as a CORS request:
When HTML form elements initiate POST requests, the mode for those POSTs also defaults to no-cors — in the same way that embedded resources have their mode defaulted to no-cors. However, unlike the no-cors mode GET requests for embedded resources, browsers do send the Origin header for those no-cors mode POSTs initiated from HTML form elements.
Also, for completeness here and to be clear: For navigations, browsers send no Origin header. That is, if a user navigates directly to a resource — by pasting a URL into a browseran address bar, or by following a link from another web document — then browsers send no Origin header.