Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "origin" in allowedHeaders #247

Closed
wants to merge 1 commit into from
Closed

Missing "origin" in allowedHeaders #247

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 2, 2018

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

There is missing "origin" in allowedHeaders, docs says that it should be in connection.headers.
@alexander-akait
Copy link

/cc @brycekahle friendly ping

@egasimus
Copy link

@evilebottnawi @brycekahle just confirming: this causes breakage in webpack-dev-server@3.1.13

@alexander-akait
Copy link

@egasimus yep

@egasimus
Copy link

@majek ?

@brycekahle
Copy link
Contributor

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

for key in ['referer', 'x-client-ip', 'x-forwarded-for', \

@alexander-akait
Copy link

@brycekahle please clarify

@brycekahle
Copy link
Contributor

@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.

@carlosgeos
Copy link

@brycekahle you are right. There was a change in webpack-dev-server, specifically in webpack/webpack-dev-server#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 😛 a71a1e5

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

@brycekahle
Copy link
Contributor

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.

@alexander-akait
Copy link

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

@brycekahle
Copy link
Contributor

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

I don't understand. Can you rephrase?

@alexander-akait
Copy link

@brycekahle why we can't merge this PR?

@brycekahle
Copy link
Contributor

@brycekahle why we can't merge this PR?

For the same reason that #247 (comment) states. Origin is meaningless, if SockJS uses an iframe middleman.

@ghost
Copy link
Author

ghost commented Jan 10, 2019

@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

@brycekahle
Copy link
Contributor

@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.

@alexander-akait
Copy link

@brycekahle maybe you better understand problem trying webpack-dev-server@3.1.13, now we use this workaround webpack/webpack-dev-server@1dfd4fb, but it is very hacky

@brycekahle
Copy link
Contributor

@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.

@alexander-akait
Copy link

@brycekahle maybe we can add option for this?

@brycekahle
Copy link
Contributor

@brycekahle maybe we can add option for this?

This is what I'm suggesting in #247 (comment) 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?

@alexander-akait
Copy link

@brycekahle can you clarify? We just need origin header 😄

@brycekahle
Copy link
Contributor

can you clarify? We just need origin header

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

@alexander-akait
Copy link

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

@mkArtakMSFT
Copy link

Hi folks. Why isn't this PR merged? It causes so much pain on the dependent frameworks. Specifically: dotnet/aspnetcore#7812 and others too.

@brycekahle
Copy link
Contributor

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

@mkArtakMSFT
Copy link

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.

@brycekahle
Copy link
Contributor

@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.

@rodrifmed
Copy link

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
Copy link

@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

@ghost ghost closed this by deleting the head repository Oct 22, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants