Skip to content

CORS headers issue: origins filter still get ignored when emitting "Transport unknown" error #3415

@fedulovivan

Description

@fedulovivan

Found that CORS header Access-Control-Allow-Origin is still generated for any Origin ignoring origins filter.

This is related to already reported and closed issues #449, #331, #2850 and pr #452

Steps to reproduce (here is full commit with reproduction scenario in my app):

  1. Create server instance and restrict origins as:
const io = SocketIo(server, { origins: 'http://localhost:8888' });
  1. Use curl and send GET request (note the terminating slash):
curl -GET -H "Origin: http://wertwertffff.com" --verbose http://localhost:8888/socket.io/

Expected behavior:
403 HTTP code and corresponding error is generated, no Access-Control-Allow-* headers are present in response.

Actual result:

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET /socket.io/ HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.47.0
> Accept: */*
> Origin: http://wertwertffff.com
> 
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Origin: http://wertwertffff.com
< Date: Mon, 04 Mar 2019 16:06:20 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
* Connection #0 to host localhost left intact
{"code":0,"message":"Transport unknown"}

Moreover, such behavior also causes security scanner (was tested with Burp Suite) to report websockets url as faulty.

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