# Khaos Websocket Testing

> Methodology for detecting WebSocket vulnerabilities including auth bypass, subscription hijacking, and unauthenticated channels in authorized assessments

- Skill: `henriqqw/khaos-websocket-testing` (Agent Skill)
- Install (CLI): `npx get-skill add henriqqw/khaos-websocket-testing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/henriqqw/khaos-websocket-testing/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: henriqqw (https://skillmd.com/u/henriqqw)
- Updated: 2026-11-18
- Page: https://skillmd.com/skills/henriqqw/khaos-websocket-testing

---


# 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 onerror=alert(1)>"}' | \
  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 `owner` and `non-owner` profiles — 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-eof` exits after one round-trip; pipe payloads via stdin
- Some WS endpoints require a valid HTTP upgrade first — use `khaos_http_request` to capture the `101` and extract the `Sec-WebSocket-Accept` for replay
- Always prefer `wss://` in scope; test `ws://` only when explicitly in scope

