Skip to content
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

403 Forbidden on POST with Bad handshake method #1390

Closed
zhangzheng7856 opened this issue Nov 2, 2020 · 11 comments
Closed

403 Forbidden on POST with Bad handshake method #1390

zhangzheng7856 opened this issue Nov 2, 2020 · 11 comments
Milestone

Comments

@zhangzheng7856
Copy link

return {"code":2,"message":"Bad handshake method"}

what it mean?

and how can i resolve it?

@lcherone
Copy link

lcherone commented Nov 6, 2020

Check client and server versions are the same, connecting to v3.0.0 server with a v2.x.x client won't work, with this exact error. Its due to the sid not being passed along.

@darrachequesne
Copy link
Member

@lcherone I don't think that's related to the v3 release, as it was not actually released when the issue was created 5 days ago. Or did that happen with a release candidate version?

@zhangzheng7856 could you please give additional details? Are you using the JS server/client? Which version?

The error is thrown here: https://github.com/socketio/engine.io/blob/4.0.1/lib/server.js#L137

Which means the server receives an HTTP request that is not a GET, but without a sid, which is invalid.

Possibly related: socketio/engine.io-client#636

@travisnguyen20
Copy link

@lcherone You are correct. I have the same issue because the client-side using version 3.0.0 that release 2 days ago while the server-side uses laravel-echo-server that using 2.x.x version.

@lcherone
Copy link

lcherone commented Nov 7, 2020

@travisnguyen20 It happened to me too, had old project which used 2.3.0 which just copied, then when coding the server part I did npm i socket.io which installed v3, then spent a few hours debugging why it's broke, then noticed the version diffs, out of a whim changed socket.io-client to match "socket.io-client": "^3.0.0", run npm i and walla all working again. Thought id look here for the same issue and then posted the suggestion. Think it might catch a few peeps out as error is not at all helpful, and one thing I noticed is that it works just fine in node but will error only when used in the browser.

Is all todo with the recent sid change I think, as it was borking on this line: https://github.com/socketio/socket.io-client/blob/master/lib/socket.ts#L228 if over websocket, but when doing polling would get the OPs Bad handshake json error.

Edit, here's an example of it not working: https://glitch.com/edit/#!/socket-io-sid?path=views%2Findex.html%3A13%3A22

@dalexhd
Copy link

dalexhd commented Nov 7, 2020

Okay... 3 hours facing this problem xd. My head is literally exploded right now!

So it seems I'm not the only one with this problem right?

@darrachequesne
Copy link
Member

@dalexhd I'm not sure I understand. Do you have the same version of Socket.IO on both sides?

@dalexhd
Copy link

dalexhd commented Nov 8, 2020

Yes the same versión of socket.io client.

darrachequesne added a commit to socketio/engine.io-client that referenced this issue Nov 17, 2020
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
@anselmpaul
Copy link

@darrachequesne I'm hijacking this thread for a similar issue, mentioned here #1140 (comment). Could you clarify if this is a bug or a breaking change between v2.3 and v3.0?

@darrachequesne
Copy link
Member

darrachequesne commented Nov 25, 2020

This is indeed a bug. It should be fixed by socketio/engine.io-client@1c8cba8, included in engine.io-client@4.0.4 and socket.io-client@3.0.3 (625d146).

Can anyone confirm?

@darrachequesne darrachequesne added this to the 3.0.3 milestone Nov 25, 2020
@mcarnoky001
Copy link

I installed version 3.0.3 on client and server, and this issue still persists.

@darrachequesne
Copy link
Member

I'm closing this, as I think the issue is now fixed.

@mcarnoky001 could you please open an issue with a reproducing test case? Thanks!

darrachequesne added a commit to socketio/engine.io-client that referenced this issue Dec 30, 2020
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
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

No branches or pull requests

7 participants