-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Uncatchable error for close message of 123 bytes because of encoding issues #1868
Comments
The close reason must be UTF-8 encoded. This check Lines 117 to 121 in a74dd2e
is only used when you directly calls That code cannot be reached if the other peer sends an invalid close frame because:
So this line Line 473 in a74dd2e
can only give you an UTF-8 encoded close reason string whose byte length is 123 bytes or less. |
The issue seems to be that we don't have Needless to say this is a pretty serious denial-of-service issue as it will normally bring the whole process down and is trivially exploitable by an attacker. So at the very least the exception needs to be caught in |
Ok, it makes sense. Thank you.
This. I'll make |
Description
If the other side has a problem and closes the websocket-connection with an message this message must not be greater than 123 bytes, otherwise an error will be thrown (that is not catchable by the client code, there needs to be an "unhandled exception handler" for those errors.
The issue is, the message itself is exactly 123 bytes long (and shouldn't throw), but the byte-message will be converted to a string before checking the bytelength of the string. If there are encoding issues some � will be inserted in the string, afterwards the bytelength of the string is greater than 123 and the error is thrown.
String-Conversion:
ws/lib/receiver.js
Line 473 in 114de9e
ByteLength-Check:
ws/lib/sender.js
Lines 117 to 121 in 114de9e
Reproducible in:
Steps to reproduce:
Easiest way to check this issue is pure node (without the package):
This happends quite easily, if the "closer" doesn't validate the utf8-correctness of the shortened byte-message. This happens if the message just get cuts after 123 bytes => removes a byte from a character.
Expected result:
Either allow it (check the bytelength of the Buffer before converting it to string) or throw the error in the caller stack => The user needs to be able to handle this.
Actual result:
Uncatchable Error (outside of caller stack).
The text was updated successfully, but these errors were encountered: