Executive brief
Gorilla WebSocket is a popular Go library for building real-time bidirectional communication channels using the WebSocket protocol. Versions prior to 1.5.3 used a weak random number generator to create security tokens (mask keys) that protect WebSocket frames from tampering. An attacker who can predict these tokens could inject malicious data into WebSocket connections, potentially compromising the confidentiality and integrity of communications relying on this library.
Technical details
This vulnerability is a use of cryptographically weak PRNG (CWE-338). The root cause is that gorilla/websocket used Go's math/rand package to generate WebSocket frame masking keys prior to version 1.5.3. WebSocket masking keys must be unpredictable to prevent content injection attacks; however, math/rand produces deterministic output when seeded with a known value. An attacker with knowledge of the PRNG seed can predict or recover mask keys and inject content into WebSocket connections. The attack requires network access to a WebSocket connection but no authentication or user interaction. The fix, released in v1.5.3, replaces math/rand with crypto/rand (commit d67f4185), which provides cryptographically secure randomness.
Affected products
- Gorilla WebSocket < 1.5.3
Timeline
- 2026-06-12: disclosed: Advisory published to GitHub Security Advisory Database
- 2026-08-24: advisory: Published to GitHub Advisory Database
- 2026-06-14: patched: Fix released in v1.5.3 (commit d67f4185)
References
- https://github.com/canolgun-commits/websocket/security/advisories/GHSA-w67g-5rqw-f597
- https://github.com/gorilla/websocket/commit/d67f41855da42d7bccd9ef050c49f7e54e783b95
- https://github.com/gorilla/websocket/releases/tag/v1.5.3
- https://api.github.com/repos/canolgun/websocket/security-advisories/GHSA-w67g-5rqw-f597