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

WebSocket Client handshake headers (Authorization) #1286

Closed
1 of 2 tasks
supar opened this issue Apr 8, 2019 · 3 comments
Closed
1 of 2 tasks

WebSocket Client handshake headers (Authorization) #1286

supar opened this issue Apr 8, 2019 · 3 comments

Comments

@supar
Copy link

supar commented Apr 8, 2019

Note: for support questions, please use one of these channels: stackoverflow or slack

For bug reports and feature requests for the Swift client, please open an issue there.

For bug reports and feature requests for the Java client, please open an issue there.

You want to:

  • report a bug
  • request a feature

Current behaviour

According to the documentation websocket transport will not append header cause the WebSocket handshake does not honor custom headers. (For background see the WebSocket protocol RFC)

Steps to reproduce (if the current behaviour is a bug)

Expected behaviour

It seems to me this is not exactly what RFC explains. Let's read item 12 in the section 4:

The request MAY include any other header fields, for example,
cookies [RFC6265] and/or authentication-related header fields
such as the |Authorization| header field [RFC2616], which are
processed according to documents that define them.

Please, add handshake headers overwrite support for websocket transport

Setup

  • OS:
  • browser:
  • socket.io version:

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@SergeyCherman
Copy link

SergeyCherman commented May 15, 2019

I was encountering the same thing when trying to find a way to do auth for my websockets. From what I've seen so far auth via headers in websockets is not recommended. Multiple sources have pointed to using a ticketing system described here: https://devcenter.heroku.com/articles/websocket-security

@Arshardh
Copy link

Arshardh commented Dec 9, 2019

The limitation I see for using headers for auth is that javascript does not support custom headers for the websocket handshake. I haven't come across any material that mentions auth via headers in websockets is not recommended. In fact even the spec mentions:

The request MAY include any other header fields, for example, cookies [RFC6265] and/or authentication-related header fields such as the |Authorization| header field [RFC2616], which are processed according to documents that define them.

@darrachequesne
Copy link
Member

For future readers, please see https://stackoverflow.com/a/4361358

I'm afraid there is nothing we can at the Socket.IO level.

Slightly related: the auth option has been added in Socket.IO v3:

// client
const socket = io({
  auth: {
    token: "abcd"
  }
});

// server
io.use((socket, next) => {
  const token = socket.handshake.auth.token;
  // check token, then
  next();
});

Documentation: https://socket.io/docs/v3/client-initialization/#auth

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

4 participants