CVE-2021-41281: Matrix synapse Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-3hfw-x7gx-437c
CVSS 7.5
CWE-22
Published
Advisory Summary

CVE-2021-41281 is a HIGH (CVSS 7.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Matrix synapse libraries in the PyPI ecosystem. The issue involves path traversal in matrix synapse. Remediation is available by upgrading affected packages to version 1.47.1.

CVE-2021-41281 at a Glance

CVE Identifier CVE-2021-41281
GHSA Identifier GHSA-3hfw-x7gx-437c
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Matrix synapse
Package Ecosystem PyPI
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:H/A:N).

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 High (I:H)
Availability None (A:N)

How to Fix CVE-2021-41281

To remediate this vulnerability, upgrade all affected Matrix synapse 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-synapse fixed: 1.47.1
pip install matrix-synapse>=1.47.1
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-synapse

How to Check if You Are Affected

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

pip show matrix-synapse

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Matrix synapse, 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 Synapse instances with the media repository enabled can be tricked into downloading a file from a remote server into an arbitrary directory, potentially outside the media store directory. The last two directories and file name of the path are chosen randomly by Synapse and cannot be controlled by an attacker, which limits the impact. Homeservers with the media repository disabled are unaffected. Homeservers configured with a federation whitelist are also unaffected. ### Patches Server administrators should upgrade to 1.47.1 or later. ### Workarounds Server administrators using a reverse proxy could, at the expense of losing media functionality, block the following endpoints: * `/_matrix/media/r0/download/{serverName}/{mediaId}` * `/_matrix/media/r0/download/{serverName}/{mediaId}/{fileName}` * `/_matrix/media/r0/thumbnail/{serverName}/{mediaId}` Alternatively, non-containerized deployments can be adapted to use the hardened systemd config, located at `contrib/systemd/override-hardened.conf`. ### References n/a ### For more information If you have any questions or comments about this advisory, e-mail us at security@matrix.org.

CVE-2021-41281 Affected Matrix synapse Versions

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

References

Frequently Asked Questions

What is CVE-2021-41281?
CVE-2021-41281 is a security vulnerability in Matrix synapse involving Path traversal in Matrix Synapse under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Matrix synapse versions are affected?
Affected versions include releases prior to 1.47.1 across affected packages: matrix-synapse.
What version fixes CVE-2021-41281?
Upgrading to 1.47.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is matrix-synapse affected?
Yes, matrix-synapse is affected in releases prior to 1.47.1. Upgrade your dependency to 1.47.1 or later.
What is the CVSS score of CVE-2021-41281?
CVE-2021-41281 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:H/A:N.
What CWE is associated with CVE-2021-41281?
CVE-2021-41281 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2021-41281?
Run the dependency tree command: 'pip show matrix-synapse'. 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-3hfw-x7gx-437c",
  "modified" : "2024-09-24T15:47:18Z",
  "published" : "2021-11-23T21:58:56Z",
  "aliases" : [ "CVE-2021-41281" ],
  "summary" : "Path traversal in Matrix Synapse",
  "details" : "### Impact\n\nSynapse instances with the media repository enabled can be tricked into downloading a file from a remote server into an arbitrary directory, potentially outside the media store directory.\n\nThe last two directories and file name of the path are chosen randomly by Synapse and cannot be controlled by an attacker, which limits the impact.\n\nHomeservers with the media repository disabled are unaffected. Homeservers configured with a federation whitelist are also unaffected.\n\n### Patches\nServer administrators should upgrade to 1.47.1 or later.\n\n### Workarounds\nServer administrators using a reverse proxy could, at the expense of losing media functionality, block the following endpoints:\n\n* `/_matrix/media/r0/download/{serverName}/{mediaId}`\n* `/_matrix/media/r0/download/{serverName}/{mediaId}/{fileName}`\n* `/_matrix/media/r0/thumbnail/{serverName}/{mediaId}`\n\nAlternatively, non-containerized deployments can be adapted to use the hardened systemd config, located at `contrib/systemd/override-hardened.conf`.\n\n### References\nn/a\n\n### For more information\n\nIf you have any questions or comments about this advisory, e-mail us at security@matrix.org.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "matrix-synapse"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.47.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/synapse/security/advisories/GHSA-3hfw-x7gx-437c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-41281"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/synapse/commit/91f2bd090"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/matrix-org/synapse"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/matrix-org/synapse/releases/tag/v1.47.1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/matrix-synapse/PYSEC-2021-436.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/EU7QRE55U4IUEDLKT5IYPWL3UXMELFAS"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/N3WY56LCEZ4ZECLWV5KMAXF2PSMUB4F2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-11-23T18:44:39Z",
    "nvd_published_at" : "2021-11-23T20:15:00Z"
  }
}