-
Notifications
You must be signed in to change notification settings - Fork 0
bugfix: client: verify the handshake response headers #8
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ local req_sock = ngx.req.socket | |
| local ngx_header = ngx.header | ||
| local req_headers = ngx.req.get_headers | ||
| local str_lower = string.lower | ||
| local str_match = string.match | ||
| local char = string.char | ||
| local str_find = string.find | ||
| local sha1_bin = ngx.sha1_bin | ||
|
|
@@ -85,7 +86,13 @@ function _M.new(self, opts) | |
| end | ||
|
|
||
| if protocols then | ||
| ngx_header["Sec-WebSocket-Protocol"] = protocols | ||
| -- RFC 6455 section 4.2.2: the server selects exactly one subprotocol | ||
| -- from the client's list, so answer with the first one offered | ||
| -- instead of echoing the whole list back | ||
| local selected = str_match(protocols, "[^,%s]+") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Reject malformed subprotocol offers before selecting. The pattern Validate the full offer and reject invalid values before sending the handshake response. 🤖 Prompt for AI Agents |
||
| if selected then | ||
| ngx_header["Sec-WebSocket-Protocol"] = selected | ||
| end | ||
| end | ||
| ngx_header["Upgrade"] = "websocket" | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.