Skip to main content
MediumClient-sideOWASP A02:2021CWE-598

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

  1. 1Send the auth token as the first message after the WebSocket connection opens, rather than in the URL.
  2. 2If the server framework supports it, pass a subprotocol-encoded or header-based token instead.
  3. 3Rotate any tokens that may already have been logged via this pattern.

Code examples

Authenticate after connecting

JavaScript
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.

See every client-side check

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.

Propose a checkHow a check is built

Scan your own site for websocket url carries auth token in query string

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

WebSocket URL Carries Auth Token in Query String | VulnRadar