CVE-2021-21333: HTML injection in email and account expiry notifications in matrix-synapse
Summary
CVE-2021-21333: HTML injection in email and account expiry notifications. Affects matrix-synapse versions < 1.27.0. Fixed in 1.27.0. How to fix ↓
Also tracked for
- matrix-synapse · Debian:13
The same CVE-2021-21333 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
matrix-synapse is an open-source Python package that provides a reference implementation of the Matrix communication protocol. It is used to create and manage Matrix homeservers, allowing users to communicate securely and in real-time. The package includes features such as missed message notifications and account expiry notifications.
Vulnerability Detail
The vulnerability identified as CVE-2021-21333 involves HTML injection in email and account expiry notifications. When sending notification emails for missed messages or expiring accounts, the package is susceptible to HTML injection. This allows an attacker to insert forged content into the email, potentially leading to various malicious activities. It is important to note that the account expiry feature is not enabled by default, and the HTML injection is not controllable by an attacker.
How To Fix
Latest published version: 1.163.0 as of 22 Oct 2026
pip install --upgrade "matrix-synapse==1.163.0"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
1.27.0
This is the first release that contains the fix.
pip install --upgrade "matrix-synapse==1.27.0"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
For missed messages notifications:
To mitigate the HTML injection vulnerability in missed messages notifications, you can override the notif.html, notif_mail.html, and room.html templates with custom templates that manually escape the variables using Jinja2's escape filter. This can be achieved by modifying the email.template_dir setting.
For account expiry notifications:
-
If you do not require the account expiry feature, it is recommended to disable it by setting
account_validity.enabledto false. -
If you still need to use account expiry notifications, you can create a custom template that manually escapes the variables using Jinja2's
escapefilter. This can be done by overriding thenotice_expiry.htmltemplate and configuring theemail.template_dirsetting.
Conclusion
In conclusion, the matrix-synapse package is vulnerable to HTML injection in email and account expiry notifications. To mitigate this vulnerability, it is crucial to update the package to version 1.27.0 or later. Additionally, workarounds such as overriding templates and disabling the account expiry feature can be implemented. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for matrix-synapse →
FAQ
The vulnerability allows an attacker to inject forged content into notification emails, potentially leading to various malicious activities. However, it is important to note that the account expiry feature is not enabled by default, and the HTML injection is not controllable by an attacker.
To fix this vulnerability, update the matrix-synapse package to version 1.27.0 or later. This update includes the necessary patches to address the HTML injection issue.
Yes, there are workarounds available. For missed messages notifications, you can override the relevant templates with custom templates that manually escape the variables. For account expiry notifications, you can disable the feature or create a custom template that escapes the variables.
Yes, you can still use account expiry notifications. If you require this feature, you can create a custom template that manually escapes the variables to mitigate the HTML injection vulnerability.
Yes, the CVSS score for this vulnerability is 6.1.
References
Related vulnerabilities
Recent vulnerabilities recorded for matrix-synapse.