Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is WebSocket Security?

WebSocket security addresses the controls a persistent, full-duplex connection does not inherit from HTTP: origin checking, per-message authorisation, and connection limits.

Illustration for the cybersecurity term WebSocket Security
Home / Blog / Cybersecurity Terms / What Is WebSocket Security?
17 November 2026

What Is WebSocket Security?

What Is WebSocket Security?

A WebSocket connection starts life as an HTTP request carrying an Upgrade header and then stops being HTTP altogether. From that point the two ends exchange messages in both directions over one long-lived connection, with no per-request headers, no status codes, and none of the middleware that was quietly applying your security controls. Chat, trading, collaborative editing, live dashboards, and notification delivery all rely on this, and the controls have to be rebuilt deliberately.

The Handshake Is the Only Gate

Because authentication and authorisation checks usually run during the HTTP handshake, that moment carries disproportionate weight. Two consequences follow.

The first is cross-site WebSocket hijacking. The same-origin policy does not apply to the WebSocket constructor, so a page on any domain can open a connection to your endpoint, and the browser attaches the victim’s cookies automatically. If the handshake authenticates by cookie and nothing checks the Origin header, the attacker’s page now holds an authenticated channel and can both send messages and read everything the server pushes. This is cross-site request forgery with a read channel attached, which makes it considerably worse.

The second is staleness. A connection authenticated at 09:00 is still open at 17:00. Token expiry, password change, session revocation, and permission changes have no effect unless the server rechecks, and most servers do not.

Controls at the Handshake

  1. Validate the Origin header against an exact allow-list and reject anything else. The header is set by the browser and cannot be altered by page script, which makes it reliable against this specific attack even though a non-browser client can forge it.
  2. Require an unguessable token as a query parameter or in the first message, rather than relying on an ambient cookie. The subprotocol header can carry it where the client library allows.
  3. Use wss:// exclusively. A plain ws:// connection is clear text, and a page loaded over HTTPS that opens one will be blocked as mixed content in any case.
  4. Apply the same rate limits to the handshake as to any other authentication-bearing endpoint, as covered in rate limiting.

Controls on Every Message

Treat each message as an independent request from an untrusted source, because that is what it is.

Infrastructure Considerations

Most web application firewalls and API gateways inspect the handshake and then pass frames through without examination, so a control you believe is in place may stop at the upgrade. Confirm what your edge actually does with frames rather than assuming. Logging deserves the same attention: HTTP access logs record one line for a connection that then carries thousands of messages, so message-level logging has to be built into the application if an incident is ever to be reconstructed.

Testing

Burp Suite records WebSocket traffic and allows messages to be edited and replayed, which covers most of the work. The checks worth running are a handshake from an unexpected origin, a connection with no credentials, a message referencing an object belonging to another user, oversized and malformed frames, and behaviour after the underlying session has been invalidated elsewhere. Because the same questions apply to other persistent and binary protocols, we test WebSocket endpoints alongside gRPC services during web application security testing.

FAQ – Frequently Asked Questions

What Is Cross-Site WebSocket Hijacking?

An attacker’s page opens a WebSocket connection to your endpoint from the victim’s browser. The same-origin policy does not restrict the WebSocket constructor, and cookies are attached automatically, so if the server authenticates by cookie and does not check the Origin header, the attacker gains a fully authenticated two-way channel without the victim noticing.

Is Checking the Origin Header Reliable?

Against browser-based attacks, yes, because page script cannot modify it and the browser sets it on every WebSocket handshake. It offers nothing against a non-browser client such as a script or a command line tool, which can send any value. Use it to block cross-site hijacking and rely on a token for authentication.

How Do We Handle Session Expiry on a Long-Lived Connection?

Recheck rather than assume. Store the session or token identity with the connection, revalidate it on a timer or on sensitive operations, and close the connection when it is no longer valid. Many applications also send a short-lived token periodically from the client. Without this, a connection opened in the morning retains its privileges for the whole day.

Do WebSockets Bypass Our Web Application Firewall?

Frequently, at least in part. Most firewalls and gateways inspect the HTTP handshake and then allow frames to pass without examination, so injection payloads inside messages are not seen. Check what your edge does with frames specifically, and place validation and authorisation in the application rather than depending on an inspection layer that may not apply.

Related Terms

You May Be Interested In These

What Are Kernel Rootkit Techniques?

Cybersecurity Terms

17 November 2026

What Are Kernel Rootkit Techniques?

Read More
What Is Serverless Security?

Cybersecurity Terms

17 November 2026

What Is Serverless Security?

Read More
How the WannaCry Attack Worked

Cybersecurity Terms

17 November 2026

How the WannaCry Attack Worked

Read More