Skip to content

[bug] CORS headers are not following specification #281

@akamensky

Description

@akamensky

This is copy of socketio/socket.io#1778

In my code:

io.origins('http://a.local:80');

If I do request from http://b.local:80, the response headers are:

400 Bad Request
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://b.local
Connection: close
Content-Length: 5
Content-Type: application/octet-stream
Date: Fri, 12 Sep 2014 04:24:46 GMT
Server: nginx/1.4.6 (Ubuntu)
Set-Cookie: io=***

Which is wrong because Origin header tells us that we actually are allowed there. This is also incorrect from specification point of view.
From www.w3.org:

The Access-Control-Allow-Origin header indicates whether a resource can be shared based by returning the value of the Origin request header, "*", or "null" in the response.

Same time the standard does not specify response code.

Possible solution:

  • Either return Access-Control-Allow-Origin: null (as per specs), or completely drop CORS headers as it will trigger browser to display console error of missing header (latter is my preferred option)
  • Suggestion is to change from 400 Bad Request to 403 Forbidden as it more precisely reflects actual status of response (request itself may be not _bad_, but it is not allowed there).

Please vote if you agree and I will provide PR for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions