Skip to content

Make websocket close include the status code - #854

Merged
gittiver merged 4 commits into
CrowCpp:masterfrom
davidot:add-ws-exit-status
Jul 29, 2024
Merged

gittiver merged 4 commits into
CrowCpp:masterfrom
davidot:add-ws-exit-status

Conversation

@davidot

@davidot davidot commented Jul 22, 2024 •

Copy link
Copy Markdown
Contributor

In the websocket protocol the first two bytes of the payload in a close packet indicate the status code.

⚠️ This code is not backwards compatible, as I could not find how that is handled in this project. In the most extreme case we can use a std::enable_if on the onclose handler which then puts the status code in front of the message again to ensure any user code behaves the exact same.

Fixes: #545
And also the third commit fixes #549 (at the very least the simple case)

@gittiver

Copy link
Copy Markdown
Member

HI davidot, could you update to the newest main branch? It's just for macOS build, which does not work anymore on macos11?

Comment thread include/crow/websocket.h Resolved
Comment thread include/crow/websocket.h Resolved
Comment thread include/crow/websocket.h Resolved
Comment thread tests/unittest.cpp Resolved
davidot added 3 commits July 28, 2024 20:04
The first two bytes of a WS close packet (opcode 0x8) represent
the status code, where 1000 is normal clean exit.
Otherwise this would invalidate connection leading to e.g. get_remote_ip
to already being cleaned before the onclose handler was called.
@davidot
davidot force-pushed the add-ws-exit-status branch from f8456e8 to 9f484b9 Compare July 28, 2024 19:49
@davidot

davidot commented Jul 28, 2024

Copy link
Copy Markdown
Contributor Author

Rebased on master, added enum (non-class one, can change that) and fixed 0 codes.

CI failure is a already present unit test, although it is not failing on master? It is passing for me locally

@gittiver

Copy link
Copy Markdown
Member

Restarted the ci jobs, seems GitHub had an hiccup, all run successful (except windows which takes longer....)

@gittiver gittiver left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just notized that documentation needs to be adapted.
Just changed it already.

@gittiver
gittiver merged commit 31ca145 into CrowCpp:master Jul 29, 2024
@davidot
davidot deleted the add-ws-exit-status branch July 29, 2024 23:18
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.

Serious problem where our clients are able to crash our server Websocket Close Frame Doesn't Contain Status Code

2 participants