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

Fix generating the Origin header value for websocket handshake request #12941

Merged

Conversation

amizurov
Copy link
Sponsor Contributor

@amizurov amizurov commented Oct 31, 2022

Motivation:

We have the old erroneous behavior of generating the Origin| Sec-WebSocket-Origin for client websocket handshake request (#9673). In Netty5 this fixed and auto-generation has been deleted at all, only if the client passed the Origin header via custom headers. The same we can do for Netty4 but it could potentially break some clients (unlikely), or introduce an additional parameter to disable or enable this behavior.

Modification:

Introduce new generateOriginHeader parameter in client config and generate the Origin|Sec-WebSocket-Origin header value only if it enabled. Add additional check for webSocketURI if it contains host or passed through customHeaders to prevent NPE in newHandshakeRequest().

Result:

Fixes #9673 #12933

@amizurov
Copy link
Sponsor Contributor Author

amizurov commented Oct 31, 2022

@normanmaurer , @chrisvest, @vietj , @slandelle, @ursaj Could you please take a look.

@chrisvest
Copy link
Contributor

One fixes the NPE by turning origin header generation off?

@ursaj
Copy link
Contributor

ursaj commented Oct 31, 2022

looks good

@amizurov
Copy link
Sponsor Contributor Author

amizurov commented Nov 1, 2022

One fixes the NPE by turning origin header generation off?

Added a comment to the issue #12933 how they are related.

@amizurov amizurov force-pushed the feature/ws_enable_generate_origin_header branch from efecda2 to 44bd9da Compare November 1, 2022 11:41
@amizurov
Copy link
Sponsor Contributor Author

amizurov commented Nov 3, 2022

@normanmaurer, @vietj, @slandelle Could you please review this changes, i would like to know your thoughts.

Copy link
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments related to the test-code. PTAL

@normanmaurer normanmaurer added this to the 4.1.86.Final milestone Nov 10, 2022
@normanmaurer normanmaurer merged commit ae9b823 into netty:4.1 Nov 10, 2022
@normanmaurer
Copy link
Member

@amizurov thanks a lot!

normanmaurer added a commit that referenced this pull request Nov 10, 2022
…est (#12941)

Motivation:

We have the old erroneous behavior of generating the `Origin| Sec-WebSocket-Origin` for client websocket handshake request (#9673). In Netty5 this fixed and auto-generation has been deleted at all, only if the client passed the `Origin` header via custom headers. The same we can do for Netty4 but it could potentially break some clients (unlikely), or introduce an additional parameter to disable or enable this behavior.

Modification:

Introduce new `generateOriginHeader` parameter in client config and generate the `Origin|Sec-WebSocket-Origin` header value only if it enabled. Add additional check for webSocketURI if it contains host or passed through `customHeaders` to prevent NPE in `newHandshakeRequest()`.

Result:

Fixes #9673 #12933

Co-authored-by: Norman Maurer <norman_maurer@apple.com>
Copy link
Contributor

@slandelle slandelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'm fine with fixing a broken behavior at the cost of a breaking change.

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.

Origin header is always sent from WebSocket client
5 participants