WebSocket Security Testing
Objective
Identify WebSocket vulnerabilities: missing authentication on the upgrade handshake, broken authorization on subscription channels, injection via WS frames, and lack of origin validation.
Discovery
# 1. Identify WS endpoints during crawl — katana emits ws:// and wss:// under xhr events
khaos_run_catalog_action("katana", assessment_id, endpoint)
# 2. Confirm WS endpoints with httpx header detection
khaos_run_catalog_action("httpx", assessment_id, endpoint)
# Look for: Upgrade: websocket, Connection: Upgrade, Sec-WebSocket-Accept
# 3. Check source for WS endpoint patterns
khaos_browser_inspect("ws:|wss:|WebSocket(|new WebSocket")
Authentication Gate Testing
The WebSocket upgrade handshake (HTTP GET with Upgrade: websocket) must enforce the same authentication as the REST API.
# Test 1: Upgrade without auth cookie / token
khaos_run_catalog_action("websocat", assessment_id, "wss://target/ws/endpoint")
# Expected: HTTP 401/403 on upgrade. Vulnerable: HTTP 101 Switching Protocols
# Test 2: Upgrade with expired/invalid JWT
khaos_http_request(assessment_id, {
method: "GET", url: "wss://target/ws/chat",
headers: {"Authorization": "Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiJhdHRhY2tlciJ9."}
})
# Expected: 401. Vulnerable: 101 (alg:none bypass)
# Test 3: Cookie-based upgrade — replace session cookie with another user's
# Requires two auth profiles: owner + non-owner
Subscription Hijacking / BOLA via WebSocket
After a successful authenticated connection, test whether subscription channels enforce ownership.
# Pattern: subscribe to another user's private channel
{
"action": "subscribe",
"channel": "private-user-{victim_id}" // change ID to another user's
}
# Expected: error/silence. Vulnerable: messages from victim's channel arrive
Origin Validation Bypass
# Test missing Origin check on upgrade:
khaos_http_request(assessment_id, {
method: "GET", url: "wss://target/ws",
headers: {
"Upgrade": "websocket",
"Connection": "Upgrade",
"Origin": "https://evil.com",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
"Sec-WebSocket-Version": "13"
}
})
# Expected: 403. Vulnerable: 101 (CSRF over WS)
Frame Injection / XSS via WS Messages
# Inject XSS payload as a WS message if output is reflected in DOM
echo '{"type":"message","data":"<img src=x | \
khaos_run_catalog_action("websocat", assessment_id, endpoint)
Validation Requirements
- 3 independent reproductions before marking as valid finding
- Authentication bypass: reproduce with fresh session each time (no cached state)
- BOLA: use distinct
ownerandnon-ownerprofiles — finding must show owner's data reaching non-owner - Record upgrade HTTP exchange (101 response + headers) as primary evidence
Finding Classification
| Scenario | OWASP | Severity |
|---|---|---|
| Unauthenticated WS upgrade | A01 Broken Access Control | HIGH |
| BOLA via subscription channel | A01 Broken Access Control | HIGH |
| Missing Origin check (CSRF over WS) | A01/A05 | MEDIUM |
| Frame injection → stored XSS | A03 Injection | HIGH |
| Sensitive data in unencrypted ws:// | A02 Cryptographic Failures | MEDIUM |
Notes
websocat --one-message --exit-on-eofexits after one round-trip; pipe payloads via stdin- Some WS endpoints require a valid HTTP upgrade first — use
khaos_http_requestto capture the101and extract theSec-WebSocket-Acceptfor replay - Always prefer
wss://in scope; testws://only when explicitly in scope