Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket Security

I am looking to implement web (angular) and iPhone apps using WebSockets to communicate with our server. In the past using HTTP requests we have used hashes using the request data, url, timestamp etc to authenticate and secure the requests.

As far as I am aware we can't send headers with WebSockets requests therefore I am wondering how I can secure each request.

Does anyone have any ideas or good practices?

like image 290
John Doe Avatar asked Jul 22 '15 13:07

John Doe


People also ask

Is WebSocket more secure than HTTPS?

wss is secure only because it means "WebSocket protocol over https". WebSocket protocol itself is not secure.

Can WebSockets be hijacked?

A successful cross-site WebSocket hijacking attack will often enable an attacker to: Perform unauthorized actions masquerading as the victim user. As with regular CSRF, the attacker can send arbitrary messages to the server-side application.

How does WebSocket authentication work?

Authentication FlowThe server generates a temporary external authentication token, stores it in the Authentication Cache, and returns it to the client. The client makes a WebSocket handshake request with the external authentication token passed as a query-string parameter in the handshake endpoint URL.


1 Answers

To secure your messages, use WebSockets over SSL/TLS (wss:// instead of ws://). Don't roll your own crypto.

Concerning authentication. The big difference between HTTP and WebSockets is that HTTP is a stateless protocol and WebSockets is not.

With HTTP you have to send headers (cookies, tokens, whatever) with each request. With WebSockets you establish a connection. In the first interactions you can authenticate the client and for the remainder of the connection you know the client is authenticated.

The people at Heroku have described a pattern where the client authenticates using HTTP, gets a ticket and then sends that ticket as a first message over the WebSocket connection. See https://devcenter.heroku.com/articles/websocket-security

like image 115
Pieter Herroelen Avatar answered Sep 21 '22 19:09

Pieter Herroelen