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

calling verifyClient callback multiple times results in "RSV1 must be clear" errors #1272

Closed
delasky opened this issue Jan 6, 2018 · 4 comments

Comments

@delasky
Copy link

delasky commented Jan 6, 2018

  • [ X] I've searched for any related issues and avoided creating a duplicate issue.

Description

Calling the verifyClient callback twice in verifyClient function triggers an "Invalid WebSocket frame: RSV1 must be clear"

It's not clear to me why this leads to that specific error. Calling the callback multiple times should probably be expressly forbidden with a related error message.

The error occurs when this.completeUpgrade is called twice.

I also think this might be the root cause behind #1238.

Reproducible in:

version:
Node.js version(s): 7.4.0
OS version(s): Mac OS X 10.10.5

Steps to reproduce:

  1. run the following code
let WebSocket = require('ws')

let verify = (info, cb) => {
    cb(true)
    cb(true)
}

const wss = new WebSocket.Server({ port: 8080, verifyClient: verify});

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
      console.log('received: %s', message);
    });

  ws.send('something');
});

const ws = new WebSocket('ws://localhost:8080');

ws.on('open', function open() {

  ws.send("hello");
})

Expected result:

A different error message, or ignore subsequent calls of the verifyClient callback.

Actual result:

RSV1 must be clear

@delasky delasky changed the title calling callback muli calling verifyClient callback multiple times results in "RSV1 must be clear" errors Jan 6, 2018
@lpinca
Copy link
Member

lpinca commented Jan 6, 2018

The error happens because the first call completes the handshake, all other calls write invalid data (handshake headers) on the socket.

We can add a guard to ensure the callback is only called once but in general it's user responsibility.

#1238 is probably caused by nodejs/node#17789. A patch is already available: nodejs/node#17806.

@lpinca
Copy link
Member

lpinca commented Jan 7, 2018

I think this is actually a good thing, but I'm willing to be convinced otherwise. If we prevent the callback from being called multiple times, users will never know that something is wrong on their end.

@delasky
Copy link
Author

delasky commented Jan 8, 2018

Thats fair. If i have time this week I might put in a PR to guard with a specific error, but at least now people who search in the issues can see this. Don't think its high priority

@lpinca
Copy link
Member

lpinca commented Jan 9, 2018

Ok, thank you.

@lpinca lpinca closed this as completed Jan 9, 2018
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

2 participants