Sc websocket

From ersinkoc/security-check · View interactive version

Sc websocket is an AI agent skill from the GitHub repository ersinkoc/security-check. WebSocket security flaw detection — missing origin validation, authentication bypass, and message injection

How to use this skill

Skill file

SC: WebSocket Security

Purpose

Detects WebSocket security vulnerabilities including missing origin validation, missing authentication on WebSocket upgrade, cross-site WebSocket hijacking, message injection, missing rate limiting, and sensitive data over unencrypted connections. Covers Socket.IO, ws, gorilla/websocket, and SignalR.

Activation

Called by sc-orchestrator during Phase 2 when WebSocket usage is detected.

Phase 1: Discovery

Keyword Patterns to Search

"WebSocket", "ws://", "wss://", "socket.io", "Socket(",
"io.connect(", "gorilla/websocket", "Upgrader",
"ws.Server", "WebSocketServer", "SignalR", "Hub",
"onmessage", "on('message'", "on('connection'"

Vulnerability Patterns

1. Missing Origin Validation:

// VULNERABLE: Accept any origin
var upgrader = websocket.Upgrader{
    CheckOrigin: func(r *http.Request) bool {
        return true  // Accepts connections from any origin!
    },
}

// SAFE: Validate origin
var upgrader = websocket.Upgrader{
    CheckOrigin: func(r *http.Request) bool {
        origin := r.Header.Get("Origin")
        return origin == "https://app.example.com"
    },
}

2. Missing Authentication:

// VULNERABLE: No auth check on WebSocket connection
wss.on('connection', (ws, req) => {
  ws.on('message', (msg) => { handleMessage(msg); });
});

// SAFE: Verify auth on connection
wss.on('connection', (ws, req) => {
  const token = req.url.split('token=')[1];
  if (!verifyToken(token)) { ws.close(1008, 'Unauthorized'); return; }
  ws.on('message', (msg) => { handleMessage(msg); });
});

3. Missing Message Validation:

// VULNERABLE: Trusting WebSocket message content
ws.on('message', (msg) => {
  const data = JSON.parse(msg);
  db.query(`SELECT * FROM ${data.table}`);  // Injection!
});

Severity Classification

Output Format

Finding: WS-{NNN}

Common False Positives

  1. Development servers — ws:// on localhost in development
  2. Public broadcast channels — WebSocket channels intentionally public (chat, notifications)
  3. Token-based auth in URL — authentication via query param token (valid pattern for WebSocket)
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.