CVE-2021-40823: Matrix js sdk Matrix-js-sdk Can Be Tricked Into Vulnerability

MODERATE
Advisory Identifier: GHSA-23cm-x6j7-6hq3
CVSS 5.9
CWE-327 CWE-200
Published
Advisory Summary

CVE-2021-40823 is a MODERATE (CVSS 5.9) matrix-js-sdk can be tricked into vulnerability (CWE-327: Use of a Broken or Risky Cryptographic Algorithm) affecting Matrix js sdk libraries in the npm ecosystem. The issue involves matrix-js-sdk can be tricked into disclosing e2ee room keys to a participating homeserver. Remediation is available by upgrading affected packages to version 12.4.1.

CVE-2021-40823 at a Glance

CVE Identifier CVE-2021-40823
GHSA Identifier GHSA-23cm-x6j7-6hq3
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-327: Use of a Broken or Risky Cryptographic Algorithm
Affected Product Matrix js sdk
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.9

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

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

How to Fix CVE-2021-40823

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

matrix-js-sdk fixed: 12.4.1
npm install matrix-js-sdk@12.4.1
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 matrix-js-sdk

How to Check if You Are Affected

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

npm ls matrix-js-sdk

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

Note: The npm ls matrix-js-sdk 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-327: Use of a Broken or Risky Cryptographic Algorithm, where the product uses a broken or risky cryptographic algorithm or protocol. In Matrix js sdk, 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 A logic error in the room key sharing functionality of matrix-js-sdk before 12.4.1 allows a malicious Matrix homeserver† participating in an encrypted room to steal room encryption keys from affected Matrix clients participating in that room. This allows the homeserver to decrypt end-to-end encrypted messages sent by affected clients. † Or anyone with access to the account of the original recipient of an encrypted message. Known clients affected (via their use of vulnerable versions of matrix-js-sdk): - Element Web (1.8.2 and earlier) - Element Desktop (1.8.2 and earlier) - SchildiChat Web (1.7.32-sc1 and earlier) - SchildiChat Desktop (1.7.32-sc1 and earlier) - Cinny (1.2.0 and earlier) ### Patch This was fixed in https://github.com/matrix-org/matrix-js-sdk/commit/894c24880da0e1cc81818f51c0db80e3c9fb2be9. ### Workarounds To prevent a homeserver from being able to steal the room keys, vulnerable clients can be taken offline or signed out. If signing out, care should be taken to either set up Secure Backup or export E2E room keys in order to preserve access to past messages.

CVE-2021-40823 Affected Matrix js sdk Versions

1 component(s)
Fixed Versions:
12.4.1
Product / Package Ecosystem Affected Versions Fixed Version
matrix-js-sdk
npm
< 12.4.1
12.4.1

References

Frequently Asked Questions

What is CVE-2021-40823?
CVE-2021-40823 is a security vulnerability in Matrix js sdk involving matrix-js-sdk can be tricked into disclosing E2EE room keys to a participating homeserver under CWE-327: Use of a Broken or Risky Cryptographic Algorithm.
Which Matrix js sdk versions are affected?
Affected versions include releases prior to 12.4.1 across affected packages: matrix-js-sdk.
What version fixes CVE-2021-40823?
Upgrading to 12.4.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is matrix-js-sdk affected?
Yes, matrix-js-sdk is affected in releases prior to 12.4.1. Upgrade your dependency to 12.4.1 or later.
What is the CVSS score of CVE-2021-40823?
CVE-2021-40823 has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2021-40823?
CVE-2021-40823 is classified under CWE-327: Use of a Broken or Risky Cryptographic Algorithm (The product uses a broken or risky cryptographic algorithm or protocol.).
How can I check npm dependencies for CVE-2021-40823?
Run the dependency tree command: 'npm ls matrix-js-sdk'. 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-23cm-x6j7-6hq3",
  "modified" : "2023-08-08T19:58:08Z",
  "published" : "2021-09-14T20:24:18Z",
  "aliases" : [ "CVE-2021-40823" ],
  "summary" : "matrix-js-sdk can be tricked into disclosing E2EE room keys to a participating homeserver",
  "details" : "### Impact\n\nA logic error in the room key sharing functionality of matrix-js-sdk before 12.4.1 allows a malicious Matrix homeserver† participating in an encrypted room to steal room encryption keys from affected Matrix clients participating in that room. This allows the homeserver to decrypt end-to-end encrypted messages sent by affected clients.\n\n† Or anyone with access to the account of the original recipient of an encrypted message.\n\nKnown clients affected (via their use of vulnerable versions of matrix-js-sdk):\n\n- Element Web (1.8.2 and earlier)\n- Element Desktop (1.8.2 and earlier)\n- SchildiChat Web (1.7.32-sc1 and earlier)\n- SchildiChat Desktop (1.7.32-sc1 and earlier)\n- Cinny (1.2.0 and earlier)\n\n### Patch\n\nThis was fixed in https://github.com/matrix-org/matrix-js-sdk/commit/894c24880da0e1cc81818f51c0db80e3c9fb2be9.\n\n### Workarounds\nTo prevent a homeserver from being able to steal the room keys, vulnerable clients can be taken offline or signed out. If signing out, care should be taken to either set up Secure Backup or export E2E room keys in order to preserve access to past messages.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "matrix-js-sdk"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "12.4.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/matrix-js-sdk/security/advisories/GHSA-23cm-x6j7-6hq3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-40823"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/matrix-js-sdk/commit/894c24880da0e1cc81818f51c0db80e3c9fb2be9"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/matrix-org/matrix-js-sdk"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/matrix-js-sdk/releases/tag/v12.4.1"
  }, {
    "type" : "WEB",
    "url" : "https://matrix.org/blog/2021/09/13/vulnerability-disclosure-key-sharing"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200", "CWE-327" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-09-14T18:08:41Z",
    "nvd_published_at" : "2021-09-13T19:15:00Z"
  }
}