-
Notifications
You must be signed in to change notification settings - Fork 355
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
engine.io client marks transport as open too early #636
Comments
The following
should indeed never happen (a POST without sid). That's weird. Could this be linked to using HTTP/2? |
Hi, thank you for taking a look at this issue! We have seen unauthenticated POST requests without an
Pipelining via HTTP/2 helps in getting the unauthenticated request out, but it should have never come to the point of emitting an unauthenticated request. |
Before this fix, the client could mark the polling transport as open even though the handshake packet was not received properly (for example, after a parsing error). This could lead to writes (POST requests) without "sid" query param, which failed with: ``` {"code":2,"message":"Bad handshake method"} ``` Related: - #636 - socketio/socket.io-client#1390
Before this fix, the client could mark the polling transport as open even though the handshake packet was not received properly (for example, after a parsing error). This could lead to writes (POST requests) without "sid" query param, which failed with: ``` {"code":2,"message":"Bad handshake method"} ``` Related: - #636 - socketio/socket.io-client#1390 Cherry-picked from master: 1c8cba8
Great, thank you for fixing this bug. |
You want to:
Current behaviour
Client can send unauthenticated messages on (failing?) connection startup.
Steps to reproduce (if the current behaviour is a bug)
Connect via socket.io client from Firefox.
We see a failure rate of about 1 in 2000 attempts.
engine.io server is configured with
cookie: false
-- use query parameter forauth.
Expected behaviour
Always wait for successful handshake.
Setup
Other information (e.g. stacktraces, related issues, suggestions how to fix)
Hi!
We are currently migrating to socket.io v2 (engine.io v3) and are experiencing
some issues. The below issue is about a failing handshake (polling).
The handshake is on the engine.io layer, but if you think it is higher in the
stack, please move it.
I found a socket.io POST requests in the nginx logs that had no
sid
(socket id) query parameter set -- aka are not authenticated.Currently a connection startup roughly works like this:
sid
sid
in the URL query object for following requestsUpon inspection of the code paths server/client side I am confident that this
is either caused by a (silent) server error which was not handled properly by
the client, a client side race condition or a parse error.
Currently any first packet marks the socket as open, this includes error
messages. Given that only the successful handshake contains the sid, we can end
up with a socket that is marked as ready for writes (allows POST requests), but
has no authentication added to the query.
engine.io-client/lib/transports/polling.js
Lines 132 to 135 in 7aad0d6
The race condition:
client: mark socket as writable
has to run AFTERsid
propagated -- otherwise the socket could accept/process write requests that
result in unauthenticated requests.
A log line with the 400 response code from the unauthenticated POST request
has a response size of 43, which we can translate to the error code 1 or
'Session ID unknown' [1]
Prior log lines of the initial polling/open request show a payload size of 104,
which is equal to other successful handshakes.
Given that the initial payload size matches the expected payload size, I do not
think that the payload was an error payload. Which suggests either the race
condition -- or a parse error.
This is happening for Firefox users only.
[1] error message -> payload size mapping:
https://github.com/socketio/engine.io/blob/001ca62cc4a8f511f3b2fbd9e4493ad274a6a0e5/lib/server.js#L266-L270
https://github.com/socketio/engine.io/blob/001ca62cc4a8f511f3b2fbd9e4493ad274a6a0e5/lib/server.js#L80-L86
The text was updated successfully, but these errors were encountered: