Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
WebSocket security addresses the controls a persistent, full-duplex connection does not inherit from HTTP: origin checking, per-message authorisation, and connection limits.

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.
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.
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.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.Treat each message as an independent request from an untrusted source, because that is what it is.
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.
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.
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.
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.
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.
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.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.