CVE-2023-45820: Directus Directus Crashes On Invalid WebSocket Vulnerability

HIGH
Advisory Identifier: GHSA-hmgw-9jrg-hf2m
CVSS 7.5
CWE-755
Published
Advisory Summary

CVE-2023-45820 is a HIGH (CVSS 7.5) directus crashes on invalid websocket vulnerability (CWE-755: Improper Handling of Exceptional Conditions) affecting Directus libraries in the npm ecosystem. The issue involves directus crashes on invalid websocket message. Remediation is available by upgrading affected packages to version 10.6.2.

CVE-2023-45820 at a Glance

CVE Identifier CVE-2023-45820
GHSA Identifier GHSA-hmgw-9jrg-hf2m
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-755: Improper Handling of Exceptional Conditions
Affected Product Directus
Package Ecosystem npm
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-2023-45820

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

directus fixed: 10.6.2
npm install directus@10.6.2
Verify Direct and Transitive Dependencies

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

npm ls directus

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2023-45820, inspect your project dependencies using npm:

npm ls directus

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

Note: The npm ls directus command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-755: Improper Handling of Exceptional Conditions, where the product does not handle or incorrectly handles an exceptional condition. In Directus, 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

### Summary It seems that any Directus installation that has websockets enabled can be crashed if the websocket server receives an invalid frame. This could probably be posted as an issue and I might even be able to put together a pull request for a fix (if only I had some extra time...), but I decided to instead post as a vulnerability just for the maintainers, since this seemingly can be used to crash any live Directus server if websockets are enabled, so public disclosure is not a good idea until the issue is fixed. ### Details The fix for this seems quite simple; the websocket server just needs to properly catch the error instead of crashing the server. See for example: https://github.com/websockets/ws/issues/2098 ### PoC - Start a fresh Directus server (using for example the compose file here: https://docs.directus.io/self-hosted/docker-guide.html). Enable websockets by setting `WEBSOCKETS_ENABLED: 'true'` environment variable. - run a separate node app somewhere else to send an invalid frame to the server: ``` const WebSocket = require("ws"); const websocket = new WebSocket("ws://0.0.0.0:8055/websocket"); websocket.on("open", function () { const chunk = Buffer.from("a180", "hex"); websocket._socket.write(chunk); }); ``` ### Impact The server crashes with an error: `RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear`. Server needs to be manually restarted to get back online (if there's no recovery mechanism in place, as there often isn't with simple node servers). This was confirmed on a local server, and additionally I was able to crash our staging server with the same code, just pointing to our staging Directus server running at fly.io. It seems to also crash servers running in the [directus.cloud](https://directus.cloud) service. I created https://websocket-test.directus.app/, pointed the above script to the websocket url of that instance and the server does crash for a while. It seems that in there there's a mechanism for bringing the server back up quite fast, but it would be quite trivial for anyone to DoS any server running in directus.cloud by just spamming these invalid frames to the server.

CVE-2023-45820 Affected Directus Versions

1 component(s)
Fixed Versions:
10.6.2
Product / Package Ecosystem Affected Versions Fixed Version
directus
npm
≥ 10.4.0
< 10.6.2
10.6.2

References

Frequently Asked Questions

What is CVE-2023-45820?
CVE-2023-45820 is a security vulnerability in Directus involving Directus crashes on invalid WebSocket message under CWE-755: Improper Handling of Exceptional Conditions.
Which Directus versions are affected?
Affected versions include releases prior to 10.6.2 across affected packages: directus.
What version fixes CVE-2023-45820?
Upgrading to 10.6.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is directus affected?
Yes, directus is affected in releases prior to 10.6.2. Upgrade your dependency to 10.6.2 or later.
What is the CVSS score of CVE-2023-45820?
CVE-2023-45820 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-2023-45820?
CVE-2023-45820 is classified under CWE-755: Improper Handling of Exceptional Conditions (The product does not handle or incorrectly handles an exceptional condition.).
How can I check npm dependencies for CVE-2023-45820?
Run the dependency tree command: 'npm ls directus'. 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-hmgw-9jrg-hf2m",
  "modified" : "2023-10-19T20:02:04Z",
  "published" : "2023-10-19T20:02:04Z",
  "aliases" : [ "CVE-2023-45820" ],
  "summary" : "Directus crashes on invalid WebSocket message",
  "details" : "### Summary\nIt seems that any Directus installation that has websockets enabled can be crashed if the websocket server receives an invalid frame. This could probably be posted as an issue and I might even be able to put together a pull request for a fix (if only I had some extra time...), but I decided to instead post as a vulnerability just for the maintainers, since this seemingly can be used to crash any live Directus server if websockets are enabled, so public disclosure is not a good idea until the issue is fixed.\n\n### Details\nThe fix for this seems quite simple; the websocket server just needs to properly catch the error instead of crashing the server. See for example: https://github.com/websockets/ws/issues/2098\n\n### PoC\n- Start a fresh Directus server (using for example the compose file here: https://docs.directus.io/self-hosted/docker-guide.html). Enable websockets by setting `WEBSOCKETS_ENABLED: 'true'` environment variable.\n- run a separate node app somewhere else to send an invalid frame to the server:\n\n```\nconst WebSocket = require(\"ws\");\nconst websocket = new WebSocket(\"ws://0.0.0.0:8055/websocket\");\nwebsocket.on(\"open\", function () {\n  const chunk = Buffer.from(\"a180\", \"hex\");\n  websocket._socket.write(chunk);\n});\n```\n\n### Impact\nThe server crashes with an error: `RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear`. Server needs to be manually restarted to get back online (if there's no recovery mechanism in place, as there often isn't with simple node servers). This was confirmed on a local server, and additionally I was able to crash our staging server with the same code, just pointing to our staging Directus server running at fly.io. It seems to also crash servers running in the [directus.cloud](https://directus.cloud) service. I created https://websocket-test.directus.app/, pointed the above script to the websocket url of that instance and the server does crash for a while. It seems that in there there's a mechanism for bringing the server back up quite fast, but it would be quite trivial for anyone to DoS any server running in directus.cloud by just spamming these invalid frames to the server. ",
  "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" : "npm",
      "name" : "directus"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "10.4.0"
      }, {
        "fixed" : "10.6.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/directus/directus/security/advisories/GHSA-hmgw-9jrg-hf2m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-45820"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/directus/directus/commit/243eed781b42d6b4948ddb8c3792bcf5b44f55bb"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/directus/directus"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/directus/directus/releases/tag/v10.6.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-755" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-10-19T20:02:04Z",
    "nvd_published_at" : "2023-10-19T19:15:15Z"
  }
}