CVE-2021-41281: Path traversal in Matrix Synapse
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.
Other sources
Synapse is a package for Matrix homeservers written in Python 3/Twisted. Prior to version 1.47.1, Synapse instances with the media repository enabled can be tricked into downloading a file from a remote server into an arbitrary directory. No authentication is required for the affected endpoint. The last 2 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 with a federation whitelist are also unaffected, since Synapse will check the remote hostname, including the trailing ../s, against the whitelist. Server administrators should upgrade to 1.47.1 or later. Server administrators using a reverse proxy could, at the expense of losing media functionality, may block the certain endpoints as a workaround. Alternatively, non-containerized deployments can be adapted to use the hardened systemd config.
— MITRE
Affected Software
Remediation
Patch Available
Event History
Frequently Asked Questions
What is CVE-2021-41281?
CVE-2021-41281 is a vulnerability in Synapse, a package for Matrix homeservers, which allows downloading a file from a remote server into an arbitrary directory without authentication.
How does CVE-2021-41281 affect Synapse instances with the media repository enabled?
CVE-2021-41281 affects Synapse instances with the media repository enabled by allowing the download of a file from a remote server into any directory, regardless of authentication.
What is the severity of CVE-2021-41281?
The severity of CVE-2021-41281 is high with a CVSS score of 7.5.
How can I fix CVE-2021-41281 in Synapse?
To fix CVE-2021-41281 in Synapse, update to version 1.47.1 or later. Refer to the Synapse release notes and GitHub advisory for more information.
What is CWE-22?
CWE-22 is a vulnerability category called Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), which is the category of vulnerability that CVE-2021-41281 falls under.