Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX call following 302 redirect sets origin to null

Tags:

I'm doing an AJAX call from domain A to domain B.

My domain B checks if A is in the list of allowed domains and sets the Access-Control-allow-Origin to domain A. So far, so good.

Domain B responds to the request by sending a 302 redirect to domain C using the Location header.

The AJAX call follows the redirect to domain C but has the header: Origin: null.

I expected the origin header to be set to domain A, after following the redirect.

Can anyone explain to me why the origin is set to null instead of to domain A?

Example

  1. Request from domain A to B

    GET / HTTP/1.1 Host: domain-B.com Origin: http://domain-A.com 
  2. Response from domain B :

    Access-Control-Allow-Origin: http://domain-A.com Location: http://domain-C.com 
  3. AJAX call follows the redirect to domain C:

    GET  HTTP/ 1.1 Host: domain-C.com Origin: null 
like image 469
Brrrr Avatar asked May 12 '15 14:05

Brrrr


People also ask

Does Ajax follow redirect?

ajax appears to always follow redirects.

Why request Getheader origin is null?

The Origin spec indicates that the Origin header may be set to "null". This is typically done when the request is coming from a file on a user's computer rather than from a hosted web page. The spec also states that the Origin may be null if the request comes from a "privacy-sensitive" context.

How long does a 302 redirect last?

Unlike 301 pages, 302 redirects are temporary, which means you can switch back at any time.


1 Answers

See here, this seems to suggest its related to a "privacy-sensitive" context.

Are there any browsers that set the origin header to "null" for privacy-sensitive contexts?

like image 93
Richard Cross Avatar answered Sep 19 '22 06:09

Richard Cross