How to fix: WebSocket URL Carries Auth Token in Query String
A client-side WebSocket connection is opened with an auth token, API key, or JWT passed as a URL query parameter.
Why it matters
URLs (including WebSocket connection URLs) are commonly logged by reverse proxies, load balancers, CDNs, and browser history, so a token passed this way ends up persisted in plaintext across systems that have no business seeing it.
The WebSocket handshake is an HTTP request, and its full URL, query string included, is subject to the same logging exposure as any other HTTP URL. Auth material belongs in a header or an initial post-connection message, not the URL.
How to fix it
- 1Send the auth token as the first message after the WebSocket connection opens, rather than in the URL.
- 2If the server framework supports it, pass a subprotocol-encoded or header-based token instead.
- 3Rotate any tokens that may already have been logged via this pattern.
Code examples
Authenticate after connecting
const ws = new WebSocket('wss://api.example.com/ws');
ws.onopen = () => ws.send(JSON.stringify({ type: 'auth', token }));References
Detected automatically by VulnRadar. The check id is cs-websocket-token-in-query, stable across every scan so you can filter or diff on it.
More client-side checks
- HighCSP Allows 'unsafe-inline' Scripts
- MediumCSP Allows 'unsafe-eval'
- HighpostMessage Without Origin Validation
- HighSensitive Data Stored in localStorage
- HighDOM XSS via location.hash Assignment
- Highdocument.write() in Page Scripts
- Higheval() in Client-Side JavaScript
- MediumExternal Script Without Subresource Integrity
Questions
- How severe is WebSocket URL Carries Auth Token in Query String?
- VulnRadar rates this medium severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id cs-websocket-token-in-query, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does WebSocket URL Carries Auth Token in Query String map to?
- It maps to CWE-598. In the OWASP Top 10 it falls under A02:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.