30

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
    
dur
  • 15,689
  • 25
  • 79
  • 125
Brrrr
  • 4,318
  • 4
  • 31
  • 30
  • Hello, I have a question...how you solved the problem? It is very interessant for all...Did you apply changes side domain A or side domain B? Thanks! – Alessandro Sep 27 '15 at 13:41
  • Possible duplicate of [Are there any browsers that set the origin header to "null" for privacy-sensitive contexts?](https://stackoverflow.com/questions/22397072/are-there-any-browsers-that-set-the-origin-header-to-null-for-privacy-sensitiv) – dur Jan 25 '18 at 18:00

2 Answers2

9

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?

Community
  • 1
  • 1
Richard Cross
  • 396
  • 3
  • 12
-8

I set Access-Control-Allow-Origin: null on domain A and that worked.

Viktor D
  • 136
  • 1
  • 7
  • 8
    WOW. That just defeats the purpose of CORS and is incredibly insecure. Please don't do this. – Fabien Warniez Aug 16 '17 at 16:38
  • If you do this unconditionally then they're both pretty bad. If you want to support null origins, you need to specifically return null, if you want to support any origin, but not null origins, then wildcard will work. It's best to check what the origin / referrer is first though. – Fabien Warniez Jan 29 '18 at 02:01