sockjs-node icon indicating copy to clipboard operation
sockjs-node copied to clipboard

Missing "origin" in allowedHeaders

Open Kamil93 opened this issue 7 years ago • 26 comments

There is missing "origin" in allowedHeaders, docs says that it should be in connection.headers.

Kamil93 avatar Dec 02 '18 19:12 Kamil93

/cc @brycekahle friendly ping

alexander-akait avatar Dec 22 '18 16:12 alexander-akait

@evilebottnawi @brycekahle just confirming: this causes breakage in [email protected]

egasimus avatar Dec 22 '18 20:12 egasimus

@egasimus yep

alexander-akait avatar Dec 22 '18 20:12 alexander-akait

@majek ?

egasimus avatar Dec 27 '18 17:12 egasimus

AFAICT this is not a behavior change in sockjs-node from v0.3.19.

https://github.com/sockjs/sockjs-node/blob/14a5c3cf097126bde74436d001816c53a0593d43/src/transport.coffee#L133

brycekahle avatar Dec 27 '18 22:12 brycekahle

@brycekahle please clarify

alexander-akait avatar Dec 28 '18 10:12 alexander-akait

@evilebottnawi Despite the docs indicating origin would be available, it appears that is has never been available (AFAICT). If the absense of origin is breaking webpack-dev-server, that is because of a change in that module, not sockjs-node.

brycekahle avatar Dec 31 '18 17:12 brycekahle

@brycekahle you are right. There was a change in webpack-dev-server, specifically in https://github.com/webpack/webpack-dev-server/pull/1603, in order to try and check the origin header to solve this security vulnerability: https://www.npmjs.com/advisories/725.

However, sockjs-node did provide an 'origin' header in the decorateConnection method until Feb 2012 :stuck_out_tongue: https://github.com/sockjs/sockjs-node/commit/a71a1e506e772371efe2a1570bc93c69a89bf190

The commit comment says 'it is meaningless in SockJS context' so I'll look more into this

carlosgeos avatar Jan 01 '19 15:01 carlosgeos

The commit comment says 'it is meaningless in SockJS context' so I'll look more into this

This is likely due to the fact that SockJS will utilize iframes to get around same origin restrictions, so the origin of the iframe will not match the origin of the parent document. See https://github.com/sockjs/sockjs-node#authorisation for more information.

brycekahle avatar Jan 01 '19 17:01 brycekahle

@brycekahle It was used without iframe. So it was not merged and fixed?

alexander-akait avatar Jan 04 '19 12:01 alexander-akait

It was used without iframe. So it was not merged and fixed?

I don't understand. Can you rephrase?

brycekahle avatar Jan 06 '19 04:01 brycekahle

@brycekahle why we can't merge this PR?

alexander-akait avatar Jan 09 '19 09:01 alexander-akait

@brycekahle why we can't merge this PR?

For the same reason that https://github.com/sockjs/sockjs-node/pull/247#issuecomment-451715393 states. Origin is meaningless, if SockJS uses an iframe middleman.

brycekahle avatar Jan 10 '19 00:01 brycekahle

@brycekahle but it can still be optional to use maybe? Today iframe transport is in most cases useless, but let's make origin header present only by setting an option parameter

ghost avatar Jan 10 '19 00:01 ghost

@brycekahle but it can still be optional to use maybe? Today iframe transports are in most cases useless, but let's make origin header present by setting an option parameter

I think the only secure way would be if the server knew iframe support was disabled. The disable_cors option does accomplish that, but may be too much if you still need CORS support for other transports.

brycekahle avatar Jan 10 '19 00:01 brycekahle

@brycekahle maybe you better understand problem trying [email protected], now we use this workaround https://github.com/webpack/webpack-dev-server/commit/1dfd4fb, but it is very hacky

alexander-akait avatar Jan 10 '19 08:01 alexander-akait

@evilebottnawi I understand the problem well enough, but I cannot make a change that doesn't work for all library users in a secure way.

brycekahle avatar Jan 10 '19 19:01 brycekahle

@brycekahle maybe we can add option for this?

alexander-akait avatar Jan 11 '19 11:01 alexander-akait

@brycekahle maybe we can add option for this?

This is what I'm suggesting in https://github.com/sockjs/sockjs-node/pull/247#issuecomment-452929348 but I need more input on what webpack-dev-server needs. Is turning off CORS completely sufficient? Or does it need to be more selective?

brycekahle avatar Jan 11 '19 18:01 brycekahle

@brycekahle can you clarify? We just need origin header :smile:

alexander-akait avatar Jan 11 '19 18:01 alexander-akait

can you clarify? We just need origin header

Yes, but can webpack-dev-server operate without CORS?

brycekahle avatar Jan 24 '19 23:01 brycekahle

@brycekahle yes, you can setup webpack-dev-server almost as you want

alexander-akait avatar Jan 25 '19 10:01 alexander-akait

Hi folks. Why isn't this PR merged? It causes so much pain on the dependent frameworks. Specifically: https://github.com/aspnet/AspNetCore/issues/7812 and others too.

mkArtakMSFT avatar Aug 02 '19 18:08 mkArtakMSFT

@mkArtakMSFT Can you explain how having origin in the allowed headers would solve your issue?

brycekahle avatar Aug 02 '19 19:08 brycekahle

I think this comment says it all: https://github.com/webpack/webpack-dev-server/pull/1608/files#diff-15fb51940da53816af13330d8ce69b4eR47

What's happening in ASP.NET Core case, we start the dev server as a seprate process and proxy all the requests to it. Without the origin header browser can't distinguish between having a direct connection to the SPA's dev server versus a reverse-proxy.

mkArtakMSFT avatar Aug 02 '19 22:08 mkArtakMSFT

@mkArtakMSFT When you say "dev server", do you mean webpack-dev-server? or something else?

Without the origin header browser can't distinguish

This PR would not affect anything regarding the browser's ability to read the Origin header. This PR is for the node.js server.

Please also read the rest of this thread. There are security concerns regarding the Origin header, specifically with iframe-based transports. I cannot simply allow the Origin header for everyone, because it would not be accurate in all cases. webpack-dev-server was able to use their patch because of the constraints around how that is used. Those constraints do not apply to everyone using SockJS.

brycekahle avatar Aug 03 '19 02:08 brycekahle

Hi @brycekahle , I'm facing a similar problem with not having the origin in the header.

My problem is to connect to the websocket we have a list of allowed origins, for security reasons.

Without know the origin and check if it is part of the allowed origin list, everyone can connect to the websocket.

Do you have a solution for this problem? I'm trying to avoid apply the workaround mentioned

rodrifmed avatar Aug 10 '23 19:08 rodrifmed

@brycekahle The documentation is wrong as well, it says:

Property: headers (object) Hash containing various headers copied from last receiving request on that connection. Exposed headers include: origin, referer and x-forwarded-for (and friends). We explicitly do not grant access to cookie header, as using it may easily lead to security issues (for details read the section "Authorisation").

Source: https://github.com/sockjs/sockjs-node#connection-instance

But the origin is not included

rodrifmed avatar Aug 10 '23 20:08 rodrifmed