Websocket api security

From xalgorix/xalgorix · View interactive version

Websocket api security is an AI agent skill from the GitHub repository xalgorix/xalgorix. WebSocket API security testing — upgrade authentication and Origin/CSWSH hijacking, per-message authorization bypass, frame injection, token lifecycle on reconnect, and unthrottled resource consumption on the WS path

How to use this skill

Skill file

WebSocket API Security

Purpose

Test real-time WebSocket APIs for handshake authorization gaps (CSWSH), message-level authorization bypass, injection inside frames, and resource-consumption weaknesses specific to the WS path.

Preconditions

Attack Surface Signals

Methodology

Step 1: Handshake and Origin (CSWSH)

# Does the server validate Origin on upgrade? Cookie-auth sockets that skip
# validation are hijackable cross-site.
for origin in "https://target.com" "https://evil.com" "null" "https://target.com.evil.com"; do
  curl -sk -i -N "https://TARGET/socket" \
    -H "Connection: Upgrade" -H "Upgrade: websocket" \
    -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
    -H "Origin: $origin" | head -1
done

CSWSH confirmed when a connection bearing a foreign/absent Origin still receives the victim's real-time data (i.e., a cookie-authenticated session usable from attacker-controlled origins).

Step 2: Per-Message Authorization

# Auth often enforced ONLY at upgrade. Connect legitimately, then:
# - subscribe to channels/rooms belonging to another user
# - request objects by ID you do not own (BOLA over WS)
# - send admin-style messages (BFLA over WS)
import asyncio, websockets, json
async def attack():
    async with websockets.connect("wss://TARGET/socket", extra_headers={"Authorization":"Bearer LOW"}) as ws:
        await ws.send(json.dumps({"action":"subscribe","channel":"admin-alerts"}))
        print(await asyncio.wait_for(ws.recv(), 5))
asyncio.run(attack())

A finding requires another user's/channel's real data returned in frames — never just an ACK.

Step 3: Token Lifecycle on the WS Path

Step 4: Injection Inside Frames

JSON message fields are injection sinks that bypass HTTP WAFs and rate limits:
  - SQL/NoSQL into query-like fields
  - XSS into broadcast/echo/presence fields (stored then rendered)
  - command injection into server-side action fields
  - prototype pollution via __proto__ keys
Confirm with the same evidence contracts as HTTP (differential/OOB), not frame errors alone.

Step 5: Resource Consumption on the WS Path

Measure: baseline behavior vs sustained load — a finding requires the server processing beyond its control, or verifiable degradation, not just "no rate limit header".

Evidence Contract

NOT evidence: a successful upgrade alone, an ACK message, frame parse errors, no visible WS rate limit without load measurement

Common Misses

False Positives / Non-Findings

Xalgorix Tool Strategy

Stopping Rule

Every WS endpoint x every Origin variant x message-level authorization x token lifecycle stage, plus load tests where volume is authorized by the runtime policy.

Handoff

Report endpoint, the bypass class (CSWSH, message authz, injection, resource), the exact frames sent, and the authenticated data or impact received. Chain frame-based BOLA/BFLA into the corresponding API skills for deeper REST-side follow-up.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.