VAITP Dataset

← Back to the dataset

CVE-2021-21274

Synapse Matrix homeserver <1.25.0: Federation DoS via .well-known redirection

  • CVSS 6.5
  • CWE-770
  • Resource Management
  • Remote

Synapse is a Matrix reference homeserver written in python (pypi package matrix-synapse). Matrix is an ecosystem for open federated Instant Messaging and VoIP. In Synapse before version 1.25.0, a malicious homeserver could redirect requests to their .well-known file to a large file. This can lead to a denial of service attack where homeservers will consume significantly more resources when requesting the .well-known file of a malicious homeserver. This affects any server which accepts federation requests from untrusted servers. Issue is resolved in version 1.25.0. As a workaround the `federation_domain_whitelist` setting can be used to restrict the homeservers communicated with over federation.

CVSS base score
6.5
Published
2021-02-26
OWASP
A10 Server Side Request Forgery (SSRF)
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Fixed by upgrading
Yes

Solution

Update to Synapse version 1.25.0 or use the federation_domain_whitelist setting.

Vulnerable code sample

class SynapseHomeserver:
    def get_well_known_file(self, domain):
        response = self.fetch_well_known_file(domain)
        return response

    def fetch_well_known_file(self, domain):
        return f"Retrieved .well-known file from {domain}"



homeserver = SynapseHomeserver()

print(homeserver.get_well_known_file("server.com"))

Patched code sample

import re
import socket
import ipaddress

class SynapseHomeserver:
    def get_well_known_file(self, domain):
        if not self.check_domain(domain):
            raise ValueError("Unsafe domain input detected.")
        response = self.fetch_well_known_file(domain)
        return response

    def check_domain(self, domain):
        if not re.fullmatch(r"[a-zA-Z0-9.-]+", domain):
            return False

        try:
            ip = socket.gethostbyname(domain)
            ip_obj = ipaddress.ip_address(ip)
            if ip_obj.is_private or ip_obj.is_loopback or ip_obj.is_link_local:
                return False
        except Exception:
            return False

        return True

    def fetch_well_known_file(self, domain):
        return f"Retrieved .well-known file from {domain}"

homeserver = SynapseHomeserver()

print(homeserver.get_well_known_file("example.com"))

Cite this entry

@misc{vaitp:cve202121274,
  title        = {{Synapse Matrix homeserver <1.25.0: Federation DoS via .well-known redirection}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2021},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2021-21274},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2021-21274/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::