WebSocket connections require authentication before streaming
Why it matters
An unauthenticated WebSocket endpoint is an open data tap. Any client — including malicious actors scanning for open sockets — can connect and receive the full message stream without possessing a valid session. OWASP A07 (Identification & Authentication Failures) and CWE-287 both flag authentication bypasses as severe because they eliminate every downstream access control you've built. In a community platform this means private channel conversations, direct messages, and presence events are exposed to anonymous consumers the moment the server boots.
Severity rationale
Critical because any unauthenticated client receives the full real-time message stream, bypassing every downstream access control.
Remediation
Add a Socket.IO middleware that validates the bearer token on the handshake before the connection is established. Reject with an error — never open the stream first and check later.
io.use((socket, next) => {
const token = socket.handshake.auth.token;
if (!token) return next(new Error('Missing authentication token'));
try {
socket.userId = verifyToken(token).id;
next();
} catch {
next(new Error('Invalid token'));
}
});
For SSE endpoints, validate the session cookie or Authorization header in your HTTP route handler before writing the Content-Type: text/event-stream response header.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Real-Time Communication Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-287 — Improper Authentication
- owasp:2021 · A07 — Identification and Authentication Failures
- nist:rev5 · IA-3 — Device Identification and Authentication
Taxons
History
- 2026-04-18·v1.0.0·Initial import from community-realtime·automated