Repository navigation
fix(api): guard websocket message parsing and default config - #680
Conversation
pozsa
left a comment
There was a problem hiding this comment.
Thanks for catching this and offering a fix.
A few things I'd like to sort out before we merge, though.
The first is that the guard doesn't quite go far enough. JSON.parse is happy with null and the throw just moves to the line below. So we'd want to check that we actually got an object before reaching into it, not just that parsing succeeded.
Second, on the log line - I'd rather we didn't log here at all. A junk frame from a peer that hasn't authenticated yet isn't something we want in the logs. It feels like it would be better to send an error response to the client here as well, just like with an invalid token a few lines below.
Last one, could you write tests for both these changes? I know that this isn't covered today, but we would like to increase the test coverage. Feel free to extract/refactor as needed.
Thank you again for the valuable contribution.
Extract the message handler so it can be unit tested, reject anything that does not parse into an object and answer the client with an error instead of logging, and guard the nested message payload as well.
|
all three done. the object check moved into a small the log is gone, an unparsable or non object frame now gets for the tests i pulled the handler out into |
pozsa
left a comment
There was a problem hiding this comment.
Thanks for addressing all three - all looks good with very thorough test cases.
e7fb9c7
## [2.11.5](v2.11.4...v2.11.5) (2026-08-20) ### Bug Fixes * **api:** guard websocket message parsing and default config ([#680](#680)) ([e7fb9c7](e7fb9c7))
|
🎉 This PR is included in version 2.11.5 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
The websocket handler parsed incoming frames before any validation, so a non JSON frame from an unauthenticated peer threw inside the async handler and crashed the process. This guards message parsing and defaults a missing filter config.