CVE-2022-39254: Matrix nio When Matrix-nio Receives Forwarded Room Vulnerability

HIGH
Advisory Identifier: GHSA-w4pr-4vjg-hffh
CVSS 8.6
CWE-322 CWE-287
Published
Advisory Summary

CVE-2022-39254 is a HIGH (CVSS 8.6) when matrix-nio receives forwarded room vulnerability (CWE-322: Key Exchange without Entity Authentication) affecting Matrix nio libraries in the PyPI ecosystem. The issue involves when matrix-nio receives forwarded room keys, the receiver doesn't check if it requested the key from the forwarder. Remediation is available by upgrading affected packages to version 0.20.

CVE-2022-39254 at a Glance

CVE Identifier CVE-2022-39254
GHSA Identifier GHSA-w4pr-4vjg-hffh
Severity HIGH
CVSS v3.1 Base Score 8.6
CWE Classification CWE-322: Key Exchange without Entity Authentication
Affected Product Matrix nio
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 8.6

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:C/C:N/I:H/A:N).

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

How to Fix CVE-2022-39254

To remediate this vulnerability, upgrade all affected Matrix nio 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-nio fixed: 0.20
pip install matrix-nio>=0.20
Verify Direct and Transitive Dependencies

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

pip show matrix-nio

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2022-39254, inspect your installed packages using pip:

pip show matrix-nio

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

Note: The pip show matrix-nio command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-322: Key Exchange without Entity Authentication, where the product performs a key exchange with an actor without verifying the identity of that actor. In Matrix nio, 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

When matrix-nio before 0.20 requests a room key from our devices, it correctly accepts key forwards only if they are a response to a previous request. However, it doesn't check that the device that responded matches the device the key was requested from. This allows a malicious homeserver to insert room keys of questionable validity into the key store in some situations, potentially assisting in an impersonation attack. ### For more information If you have any questions or comments about this advisory, e-mail us at [poljar@termina.org.uk](mailto:poljar@termina.org.uk).

CVE-2022-39254 Affected Matrix nio Versions

1 component(s)
Fixed Versions:
0.20
Product / Package Ecosystem Affected Versions Fixed Version
matrix-nio
PyPI
< 0.20
0.20

References

Frequently Asked Questions

What is CVE-2022-39254?
CVE-2022-39254 is a security vulnerability in Matrix nio involving When matrix-nio receives forwarded room keys, the receiver doesn't check if it requested the key from the forwarder under CWE-322: Key Exchange without Entity Authentication.
Which Matrix nio versions are affected?
Affected versions include releases prior to 0.20 across affected packages: matrix-nio.
What version fixes CVE-2022-39254?
Upgrading to 0.20 (or the latest patched release for your respective branch) resolves the vulnerability.
Is matrix-nio affected?
Yes, matrix-nio is affected in releases prior to 0.20. Upgrade your dependency to 0.20 or later.
What is the CVSS score of CVE-2022-39254?
CVE-2022-39254 has a CVSS v3.1 base score of 8.6 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2022-39254?
CVE-2022-39254 is classified under CWE-322: Key Exchange without Entity Authentication (The product performs a key exchange with an actor without verifying the identity of that actor.).
How can I check PyPI dependencies for CVE-2022-39254?
Run the dependency tree command: 'pip show matrix-nio'. 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-w4pr-4vjg-hffh",
  "modified" : "2022-09-30T22:56:17Z",
  "published" : "2022-09-30T22:56:17Z",
  "aliases" : [ "CVE-2022-39254" ],
  "summary" : "When matrix-nio receives forwarded room keys, the receiver doesn't check if it requested the key from the forwarder",
  "details" : "When matrix-nio before 0.20 requests a room key from our devices, it correctly accepts key forwards only if they are a response to a previous request. However, it doesn't check that the device that responded matches the device the key was requested from.\n\nThis allows a malicious homeserver to insert room keys of questionable validity into the key store in some situations, potentially assisting in an impersonation attack.\n\n### For more information\nIf you have any questions or comments about this advisory, e-mail us at [poljar@termina.org.uk](mailto:poljar@termina.org.uk).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "matrix-nio"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.20"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/poljar/matrix-nio/security/advisories/GHSA-w4pr-4vjg-hffh"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-39254"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/poljar/matrix-nio/commit/b1cbf234a831daa160673defd596e6450e9c29f0"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/poljar/matrix-nio"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-287", "CWE-322" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-09-30T22:56:17Z",
    "nvd_published_at" : "2022-09-29T15:15:00Z"
  }
}