-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Improve Origin header handing for WebSockets #1448
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
Comments
but not if you call https://websocket.org/echo.html |
Oh my, you're right. But then, as you can see, your suggestion doesn't work either: you jump can't build the Origin header from the ws(s) url as it could be a different domain (here, WebSocket domain is "echo.websocket.org" while Origin header targets "websocket.org"). The best solution would be to honor existing "Origin" header. WDYT? |
I think that's a sensible solution: If the "Origin" header is passed use that one, otherwise construct it like in my suggested solution. |
Yes, I noticed that too but didn't have time yesterday for logging the issue. This is a separate issue. Would you mind providing your PR, please? Also, you should be using |
|
Never used Git, huh? ;-) |
…… …ured scheme for wss, close #1448 Motivation: When performing initial WebSocket HTTP request, we force Origin header. This is wrong, as Origin might use a different domain than WebSocket url. Also, when computing default Origin, it would make sense to use a secure scheme when using secured sockets. Modifications: * Don’t override existing Origin header * Use https for wss Result: It’s now possible to set Origin on a different domain. Better default
In the NettyRequestFactory the origin header is calculated this way:
.set(ORIGIN, "http://" + uri.getHost() + ":" + uri.getExplicitPort())//
this is wrong for secure wss websocket request, if you for example have an request to
wss://yourdomain.com
the origin header will behttp://yourdomain.com:443
The correct header should be calculated like this:
String origin = (uri.getScheme().equals("wss") ? "https" : "http" ) +"://"+uri.getHost() +(uri.getExplicitPort() != 80 && uri.getExplicitPort() != 443 ? uri.getExplicitPort() : "");
The text was updated successfully, but these errors were encountered: