CVE-2022-35922: Websocket Rust-WebSocket Memory Allocation Based On Vulnerability

HIGH
Advisory Identifier: GHSA-qrjv-rf5q-qpxc
CVSS 7.5
CWE-400 CWE-770 CWE-119
Published
Advisory Summary

CVE-2022-35922 is a HIGH (CVSS 7.5) rust-websocket memory allocation based on vulnerability (CWE-400: Uncontrolled Resource Consumption) affecting Websocket libraries in the crates.io ecosystem. The issue involves rust-websocket memory allocation based on untrusted length. Remediation is available by upgrading affected packages to version 0.26.5.

CVE-2022-35922 at a Glance

CVE Identifier CVE-2022-35922
GHSA Identifier GHSA-qrjv-rf5q-qpxc
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-400: Uncontrolled Resource Consumption
Affected Product Websocket
Package Ecosystem crates.io
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2022-35922

To remediate this vulnerability, upgrade all affected Websocket dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

websocket fixed: 0.26.5
Upgrade websocket to 0.26.5
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for websocket

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-35922, inspect your project dependencies for Websocket:

inspect dependencies for websocket

Analyze the terminal output to locate any version of Websocket in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.26.5), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-400: Uncontrolled Resource Consumption, where the product does not properly control the allocation and maintenance of a limited resource. In Websocket, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Impact Untrusted websocket connections can cause an out-of-memory (OOM) process abort in a client or a server. The root cause of the issue is during dataframe parsing. Affected versions would allocate a buffer based on the declared dataframe size, which may come from an untrusted source. When `Vec::with_capacity` fails to allocate, the default Rust allocator will abort the current process, killing all threads. This affects only sync (non-Tokio) implementation. Async version also does not limit memory, but does not use `with_capacity`, so DoS can happen only when bytes for oversized dataframe or message actually got delivered by the attacker. This is a security concern for you, if - your server application handles untrusted websocket connections - OR your client application connects to untrusted websocket servers ## Patches The crashes are fixed in version **0.26.5** by imposing default dataframe size limits. Affected users are advised to update to this version. Note that default memory limits are rather large (100MB dataframes and 200 MB messages), so they can still cause DoS in some environments (i.e. 32-bit). New API has been added to fine tune those limits for specific applications. ### Workarounds * Migrate your project to another, maintained Websocket library like Tungstenite. * Accept only trusted WebSocket traffic. * Filter the WebSocket traffic though some kind of proxy that ensures sanity limits on messages. * Handle process aborts gracefully and limit process memory using OS tools. ## Credits This issue was reported by [Evan Richter](https://github.com/evanrichter) at ForAllSecure and found with [Mayhem](https://forallsecure.com/mayhem-for-code) and [Cargo Fuzz](https://github.com/rust-fuzz/cargo-fuzz).

CVE-2022-35922 Affected Websocket Versions

1 component(s)
Fixed Versions:
0.26.5
Product / Package Ecosystem Affected Versions Fixed Version
websocket
crates.io
< 0.26.5
0.26.5

References

Frequently Asked Questions

What is CVE-2022-35922?
CVE-2022-35922 is a security vulnerability in Websocket involving Rust-WebSocket memory allocation based on untrusted length under CWE-400: Uncontrolled Resource Consumption.
Which Websocket versions are affected?
Affected versions include releases prior to 0.26.5 across affected packages: websocket.
What version fixes CVE-2022-35922?
Upgrading to 0.26.5 (or the latest patched release for your respective branch) resolves the vulnerability.
Is websocket affected?
Yes, websocket is affected in releases prior to 0.26.5. Upgrade your dependency to 0.26.5 or later.
What is the CVSS score of CVE-2022-35922?
CVE-2022-35922 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2022-35922?
CVE-2022-35922 is classified under CWE-400: Uncontrolled Resource Consumption (The product does not properly control the allocation and maintenance of a limited resource.).
How can I check crates.io dependencies for CVE-2022-35922?
Run the dependency tree command: 'inspect dependencies for websocket'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qrjv-rf5q-qpxc",
  "modified" : "2022-08-06T05:20:00Z",
  "published" : "2022-08-06T05:20:00Z",
  "aliases" : [ "CVE-2022-35922" ],
  "summary" : "Rust-WebSocket memory allocation based on untrusted length",
  "details" : "## Impact\nUntrusted websocket connections can cause an out-of-memory (OOM) process abort in a client or a server.\nThe root cause of the issue is during dataframe parsing.\nAffected versions would allocate a buffer based on the declared dataframe size, which may come from an untrusted source.\nWhen `Vec::with_capacity` fails to allocate, the default Rust allocator will abort the current process, killing all threads. This affects only sync (non-Tokio) implementation. Async version also does not limit memory, but does not use `with_capacity`, so DoS can happen only when bytes for oversized dataframe or message actually got delivered by the attacker.\n\nThis is a security concern for you, if\n- your server application handles untrusted websocket connections\n- OR your client application connects to untrusted websocket servers\n\n## Patches\nThe crashes are fixed in version **0.26.5** by imposing default dataframe size limits.\nAffected users are advised to update to this version.\n\nNote that default memory limits are rather large (100MB dataframes and 200 MB messages), so they can still cause DoS in some environments (i.e. 32-bit). New API has been added to fine tune those limits for specific applications.\n\n### Workarounds\n\n* Migrate your project to another, maintained Websocket library like Tungstenite.\n* Accept only trusted WebSocket traffic.\n* Filter the WebSocket traffic though some kind of proxy that ensures sanity limits on messages.\n* Handle process aborts gracefully and limit process memory using OS tools.\n\n\n## Credits\nThis issue was reported by [Evan Richter](https://github.com/evanrichter) at ForAllSecure and found with [Mayhem](https://forallsecure.com/mayhem-for-code) and [Cargo Fuzz](https://github.com/rust-fuzz/cargo-fuzz).\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "crates.io",
      "name" : "websocket"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.26.5"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/websockets-rs/rust-websocket/security/advisories/GHSA-qrjv-rf5q-qpxc"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-35922"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/websockets-rs/rust-websocket/commit/cbf6e9983e839d2ecad86de8cd1b3f20ed43390b"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/websockets-rs/rust-websocket"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/4V2EOOU5OLEHVMKAH6BALQXKDKIZRXCI"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/HYPNCM4H4OFBIZI6XMJ2DUTS54FT2TWP"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2022-0035.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-119", "CWE-400", "CWE-770" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-08-06T05:20:00Z",
    "nvd_published_at" : "2022-08-01T22:15:00Z"
  }
}