I have an API endpoint that I call from my React app. That API is on the same domain. Something like:
https://www.example.com
https://www.example.com/api/update-something
I use cross-fetch to do that request.
I was expecting to see an Origin header on my server logs. Infact, I was expecting to see Origin: https://www.example.com .
But here is what I get:
Origin: undefined
// AND I ALSO GET THESE HEADERS
"sec-fetch-dest":"empty",
"sec-fetch-mode":"cors",
"sec-fetch-site":"same-origin"
What do they mean? It's like the Origin check was already made?
For example: if I get sec-fetch-site: cross-site it means that the call was generate in another website/domain? Is that correct?
Reference:
Sec-Fetch-Site: cross-site
Sec-Fetch-Site: same-origin
Sec-Fetch-Site: same-site
Sec-Fetch-Site: none
Browsers send no
Originin same-originGETrequests, per Fetch spec requirements. ✳️Yes — browsers know:
…and browsers check all those before deciding whether to add the
Originheader; and they don’t add theOriginheader if the origins match and the method isGET.https://w3c.github.io/webappsec-fetch-metadata/#sec-fetch-site-header has details:
https://subdomain.example.comandhttps://example.comare same-site (even though not same-origin).✳️ Spec requirements causing the
Originheader to be omitted in same-originGETrequests:Whether or not the
Originheader gets added ultimately depends on the request’s “response tainting”, the value of which starts out as "basic", and which, for same-origin requests, the Fetch algorithm keeps sets to "basic", per step 12 of the “Main fetch” algorithm:Running scheme fetch causes the append a request `Origin` header algorithm to get invoked, and that causes the
Originheader to be added only if at least one of the following is true:cors"websocket"GETnorHEADBut for same-origin
GET, the response tainting isn’tcors(rather, per the requirements above, it’sbasic), the request mode isn’twebsocket, and of course the method isn’t neitherGETnorHEAD(it’sGET); thus, the algorithm requires browsers to not add anOriginheader.