WebSocket API authentication and message authorisation
A successful WebSocket handshake does not authorise every later message. Understanding websocket API authentication and message authorisation helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Authorisation determines which resources and operations an established identity may use. It must be enforced where protected data is read or changed. User interface restrictions, obscure identifiers and documentation can help usability, but they do not replace the service's own permission decision.
WebSocket is a communications protocol that provides a simultaneous two-way communication channel over a single TCP connection. It was standardized by the IETF as RFC 6455 in 2011 and is distinct from HTTP, even though it is designed to work over HTTP ports 443 and 80.
Why it matters
Consider a realistic failure: a connected user switches a record identifier and receives another account's updates.
A missing check can expose another account's information or let an ordinary user perform a privileged action. The result should be described by the actual records and operations reached, including whether access crosses a customer or organisational boundary.
An API review follows the server-side behaviour behind the interface. Direct requests, alternate methods and background operations can reveal boundaries that the normal frontend journey does not exercise.
How penetration testers check for it
Check origins, channel identity, message-level permissions and session expiry.
- Confirm that WebSocket over TLS (WSS) is used for all WebSocket connections.
- Verify that, during the initial HTTP WebSocket handshake, the Origin header field is checked against a list of origins allowed for the application.
- Verify that, if the application's standard session management cannot be used, dedicated tokens are being used for this, which comply with the relevant Session Management security requirements.
- Confirm that dedicated WebSocket session management tokens are initially obtained or validated through the previously authenticated HTTPS session when transitioning an existing HTTPS session to a WebSocket channel.
- Test nested resources, background processing and state changes.
- Confirm rejection as well as the legitimate successful journey.
How to fix it
Bind connections to trusted identity and authorise each protected message and subscription.
- Define explicit access rules and default-deny behaviour.
- Bind resource selection to trusted ownership and tenant context.
- Enforce permission checks at each protected operation.
- Maintain regression cases for unauthorised users and changed permissions.
A successful response alone does not prove unauthorised access. Establish whose resource was affected and what the caller was legitimately entitled to do.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- gRPC API metadata, method access and message limits
- Building repeatable API authorisation regression tests
- Authorisation on bulk API operations and batch requests
Read about our methodology or contact pentested.com to discuss your APIs and integrations.