Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Preserve client case for selected subprotocol#273

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nhooyr merged 1 commit intocoder:masterfromegorbunov:master
Dec 23, 2020

Conversation

egorbunov
Copy link
Contributor

@egorbunovegorbunov commentedDec 21, 2020
edited
Loading

WebSocket implementation in chromium rejects
ws connections in case server side responses with
Sec-WebSocket-Protocol header which value does
not match one of the values sent in the same header by client

In case you use subprotocols to send case-sensitive text
(for example, auth tokens) you end up with inability
to establish websocket connection from chromium.

How to reproduce:

Initialize websocket like this:

websocketOptions:=&websocket.AcceptOptions{}ifsubProtocol:=r.Header.Get("Sec-Websocket-Protocol");subProtocol!="" {websocketOptions.Subprotocols= []string{subProtocol}}...ws,err:=websocket.Accept(w,r,websocketOptions)...

After that try to establish connection from javascript in chromium (my current version is87.0.4280.88):

varws=newWebSocket(url,"ToKeN")

You will get next error:

WebSocket connection to '...' failed: Error during WebSocket handshake: 'Sec-WebSocket-Protocol' header value 'token' in response does not match any of sent values

So this PR fixes that behavior.

nhooyr reacted with heart emoji
Copy link
Contributor

@nhooyrnhooyr left a comment

Choose a reason for hiding this comment

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

Wonderful catch, thank you@egorbunov <3

accept.go Outdated
v=strings.TrimSpace(v)
for_,t:=rangestrings.Split(v,",") {
t=strings.ToLower(t)
iflower {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we shouldn't do aToLower here at all and instead rely on the caller handling case correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this code is also going to cause trouble forSec-WebSocket-Extensions. In general, I don't think HTTP header values are case insensitive so I think I made a mistake here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thinkheaderContainsToken should be the one modified to allow optional case insensitivity as that's the function used to checkConnect andUpgrade whose values are case insensitive. And then this function should be changed to not modify case at all.

egorbunov reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Rewrote the fix. Decided to renameheaderContainsToken toheaderContainsTokenIgnoreCase because this function is only used to deal withConnect andUpgrade headers.

nhooyr reacted with heart emoji
HTTP header values, as opposed to header keys,are case sensitive, but implementation of headerTokens()before that patch would return lowered values always.This old behavior could lead to chromium (v87) WebSocketrejecting connnection because negotiated subprotocol,returned in Sec-WebSocket-Protocol header (loweredbe headerToken() function) would not match one sentby client, in case client specified value with capitalletters.
Copy link
Contributor

@nhooyrnhooyr left a comment

Choose a reason for hiding this comment

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

Lovely!! Thanks again@egorbunov 🚀

egorbunov reacted with heart emoji
@nhooyrnhooyr merged commite4c3b0f intocoder:masterDec 23, 2020
nhooyr pushed a commit that referenced this pull requestJan 9, 2021
HTTP header values, as opposed to header keys,are case sensitive, but implementation of headerTokens()before this patch would return lowered values always.This old behavior could lead to chromium (v87) WebSocketrejecting connnection because negotiated subprotocol,returned in Sec-WebSocket-Protocol header (loweredbe headerToken() function) would not match one sentby client, in case client specified value with capitalletters.
nhooyr added a commit that referenced this pull requestJan 9, 2021
nhooyr added a commit that referenced this pull requestJan 9, 2021
There were a few PRs merged into the master branch that were then notmerged into the dev branch. This branch merges those changes in cleanly.-#261-#266-#273
@nhooyrnhooyr mentioned this pull requestJan 9, 2021
nhooyr added a commit that referenced this pull requestJan 9, 2021
There were a few PRs merged into the master branch that were then notmerged into the dev branch. This branch merges those changes in cleanly.-#261-#266-#273
EdgarBarrantes pushed a commit to EdgarBarrantes/websocket that referenced this pull requestAug 4, 2021
HTTP header values, as opposed to header keys,are case sensitive, but implementation of headerTokens()before this patch would return lowered values always.This old behavior could lead to chromium (v87) WebSocketrejecting connnection because negotiated subprotocol,returned in Sec-WebSocket-Protocol header (loweredbe headerToken() function) would not match one sentby client, in case client specified value with capitalletters.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
1 more reviewer

@nhooyrnhooyrnhooyr approved these changes

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@egorbunov@nhooyr

[8]ページ先頭

©2009-2025 Movatter.jp