T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/broker.py:22- Finding
Unauthenticated Network-Accessible WebSocket Broker Permits Agent Impersonation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/broker.py:22-23,scripts/broker.py:40-44,scripts/broker.py:144-181, andscripts/broker.py:217
Vulnerability Type: Missing authentication and authorization
Risk Level: HighVulnerable Code
python HOST = "0.0.0.0" PORT = 8765python async def register_agent(self, agent_id: str, websocket: websockets.WebSocketServerProtocol): """Register Agent""" self.agents[agent_id] = websocket self.connections.add(websocket) print(f"[REGISTER] Agent '{agent_id}' connected")python async def handle_connection(self, websocket: websockets.WebSocketServerProtocol): """Handle connection""" agent_id = None try: async for data in websocket: try: msg = json.loads(data) # Register if msg.get("type") == "register": agent_id = msg.get("agent_id") await self.register_agent(agent_id, websocket) await websocket.send(json.dumps({ "type": "registered", "agent_id": agent_id, "status": "online" })) # Send message elif msg.get("type") == "send": result = await self.send_message( msg.get("from", "unknown"), msg.get("to"), msg.get("message"), msg.get("priority", "normal") ) await websocket.send(json.dumps(result)) # Broadcast message elif msg.get("type") == "broadcast": result = await self.broadcast_message( msg.get("from", "unknown"), msg.get("message"), msg.ge ...[truncated 2795 chars]- Remediation
View remediation
Remediation Suggestions
- Bind to
127.0.0.1by default unless remote access is explicitly required. - Use authenticated
wss://transport for non-loopback communication. - Require a securely provisioned credential, mutually authenticated TLS certificate, or signed short-lived token during registration.
- Associate each authenticated connection with one server-verified identity.
- Ignore or reject client-supplied
fromvalues. Derive the sender from the authenticated connection. - Reject unauthorized recipients and broadcast targets according to an explicit access-control policy.
- Define safe duplicate-registration behavior instead of silently replacing an existing connection.
- Restrict the status query to authorized clients and disclose only necessary information.
- Add per-client connection, message-rate, payload-size, and queue limits.
- Add security tests covering unauthenticated registration, identity collisions, sender spoofing, unauthorized status queries, and forged broadcasts.
- Bind to
