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

Origin header for WebSocket Upgrade request always starts with "http" #723

Open
hyrth opened this issue Nov 27, 2020 · 4 comments
Open

Origin header for WebSocket Upgrade request always starts with "http" #723

hyrth opened this issue Nov 27, 2020 · 4 comments

Comments

@hyrth
Copy link

hyrth commented Nov 27, 2020

I am getting a 403 Forbidden response during WebSocket Upgrade request when connecting to a server via HTTPS (instead of 101).
The reason is a wrong "Origin" header. The header is set in method

org.glassfish.tyrus.core.Handshake.updateHostAndOrigin(final UpgradeRequest upgradeRequest).

The Origin header is always set to scheme "http" no matter which scheme was used originally:

requestHeaders.put(UpgradeRequest.ORIGIN_HEADER, Collections.singletonList("http://" + host));

@cstack89
Copy link

I'm also having this issue, is there any way to resolve it?

@hyrth
Copy link
Author

hyrth commented Feb 11, 2022

You can set the WebSocketHttpHeaders when calling SockJsClient.doHandshake(WebSocketHandler handler, @Nullable WebSocketHttpHeaders headers, URI url);

Something like this:

var httpHeaders = new WebSocketHttpHeaders();
httpHeaders.add("Origin", "https://your.server.url"); // Origin header of your server
httpHeaders.add(...); // additional headers like auth, token, ... whatever

// during handshake use your custom headers
sockJsClient.doHandshake(yourHandler, httpHeaders, "wss://your.server.url/websocket-resource");
...

I think that was our workaround.

@cstack89
Copy link

Thanks, I'm using a Spring WebSocketSompClient, but was able to pass in headers as well to the connect method.

stompClient.connect(finalUrl, header1, this);

@githopper
Copy link

FYI this bug was fixed by #783 and is included in release 1.19

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

No branches or pull requests

3 participants