Vulnerabilities in pkg:pypi/twisted

PACKAGE
Advisory Identifier: GHSA-cf56-g6w6-pqq2
Advisory Summary

CVE-2024-41810 is a MODERATE (CVSS 6.1) twisted vulnerable to html injection vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Twisted libraries in the PyPI ecosystem. The issue involves twisted vulnerable to html injection in http redirect body. Remediation is available by upgrading affected packages to version 24.7.0rc1.

6 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/twisted

6 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/twisted. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-cf56-g6w6-pqq2 CVE-2024-41810 MODERATE Twisted vulnerable to HTML injection in HTTP redirect body
GHSA-c8m8-j448-xjx7 CVE-2024-41671 MODERATE twisted.web has disordered HTTP pipeline response
GHSA-rv6r-3f5q-9rgx CVE-2022-21716 HIGH Twisted SSH client and server deny of service during SSH handshake.
GHSA-6cc5-2vg4-cc7m CVE-2019-12387 MODERATE Twisted CRLF Injection
GHSA-8r99-h8j2-rw64 - MODERATE Twisted vulnerable to HTTP Request Smuggling Attacks
GHSA-32gv-6cf3-wcmq - CRITICAL HTTP/2 DoS Attacks: Ping, Reset, and Settings Floods

CVE-2024-41810 at a Glance

CVE Identifier CVE-2024-41810
GHSA Identifier GHSA-cf56-g6w6-pqq2
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Twisted
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.1

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

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

How to Fix CVE-2024-41810

To remediate this vulnerability, upgrade all affected Twisted dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

twisted fixed: 24.7.0rc1
pip install twisted>=24.7.0rc1
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 twisted

How to Check if You Are Affected

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

pip show twisted

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Twisted, 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

### Summary The `twisted.web.util.redirectTo` function contains an HTML injection vulnerability. If application code allows an attacker to control the redirect URL this vulnerability may result in Reflected Cross-Site Scripting (XSS) in the redirect response HTML body. ### Details Twisted’s `redirectTo` function generates an `HTTP 302 Redirect` response. The response contains an HTML body, built for exceptional cases where the browser doesn’t properly handle the redirect, allowing the user to click a link, navigating them to the specified destination. The function reflects the destination URL in the HTML body without any output encoding. ```python # https://github.com/twisted/twisted/blob/trunk/src/twisted/web/_template_util.py#L88 def redirectTo(URL: bytes, request: IRequest) -> bytes: # ---snip--- content = b""" <html> <head> <meta http-equiv=\"refresh\" content=\"0;URL=%(url)s\"> </head> <body bgcolor=\"#FFFFFF\" text=\"#000000\"> <a href=\"%(url)s\">click here</a> </body> </html> """ % { b"url": URL } return content ``` If an attacker has full or partial control over redirect location due to an application bug, also known as an “Open Redirect”, they may inject arbitrary HTML into the response’s body, ultimately leading to an XSS attack. It’s worth noting that the issue is known to maintainers and tracked with GitHub [Issue#9839](https://github.com/twisted/twisted/issues/9839). The issue description, however, does not make any mention of exploitability and simply states: “…Browsers don't seem to actually render that page…” ### PoC The issue can be reproduced by running the following Twisted-based HTTP server locally: ```python from twisted.web import server, resource from twisted.internet import reactor from twisted.web.util import redirectTo class Simple(resource.Resource): isLeaf = True def render_GET(self, request): url = request.args[b'url'][0] # <-- open redirect return redirectTo(url, request) site = server.Site(Simple()) reactor.listenTCP(9009, site) reactor.run() ``` Once running, navigate to the following URL: `http://127.0.0.1:9009?url=ws://example.com/"><script>alert(document.location)</script>`, and verify that the “alert” dialog was displayed. **Note**: Due to the different ways browsers validate the redirect Location header, this attack is possible only in **Firefox**. All other tested browsers will display an error message to the user and will not render the HTML body. ### Impact If successfully exploited, the issue will allow malicious JavaScript to run in the context of the victim's session. This will in turn lead to unauthorized access/modification to victim's account and information associated with it, or allow for unauthorized operations to be performed within the context of the victim's session.

CVE-2024-41810 Affected Twisted Versions

1 component(s)
Fixed Versions:
24.7.0rc1
Product / Package Ecosystem Affected Versions Fixed Version
twisted
PyPI
< 24.7.0rc1
24.7.0rc1

References

Frequently Asked Questions

What is CVE-2024-41810?
CVE-2024-41810 is a security vulnerability in Twisted involving Twisted vulnerable to HTML injection in HTTP redirect body under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Twisted versions are affected?
Affected versions include releases prior to 24.7.0rc1 across affected packages: twisted.
What version fixes CVE-2024-41810?
Upgrading to 24.7.0rc1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is twisted affected?
Yes, twisted is affected in releases prior to 24.7.0rc1. Upgrade your dependency to 24.7.0rc1 or later.
What is the CVSS score of CVE-2024-41810?
CVE-2024-41810 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2024-41810?
CVE-2024-41810 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2024-41810?
Run the dependency tree command: 'pip show twisted'. 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-cf56-g6w6-pqq2",
  "modified" : "2025-11-04T16:51:18Z",
  "published" : "2024-07-29T17:29:36Z",
  "aliases" : [ "CVE-2024-41810" ],
  "summary" : "Twisted vulnerable to HTML injection in HTTP redirect body",
  "details" : "### Summary\n\nThe `twisted.web.util.redirectTo` function contains an HTML injection vulnerability. If application code allows an attacker to control the redirect URL this vulnerability may result in Reflected Cross-Site Scripting (XSS) in the redirect response HTML body.\n\n### Details\nTwisted’s `redirectTo` function generates an `HTTP 302 Redirect` response. The response contains an HTML body, built for exceptional cases where the browser doesn’t properly handle the redirect, allowing the user to click a link, navigating them to the specified destination.\n\nThe function reflects the destination URL in the HTML body without any output encoding. \n```python\n# https://github.com/twisted/twisted/blob/trunk/src/twisted/web/_template_util.py#L88\ndef redirectTo(URL: bytes, request: IRequest) -> bytes:\n    # ---snip---\n    content = b\"\"\"\n<html>\n    <head>\n        <meta http-equiv=\\\"refresh\\\" content=\\\"0;URL=%(url)s\\\">\n    </head>\n    <body bgcolor=\\\"#FFFFFF\\\" text=\\\"#000000\\\">\n    <a href=\\\"%(url)s\\\">click here</a>\n    </body>\n</html>\n\"\"\" % {\n        b\"url\": URL\n    }\n    return content\n```\n\nIf an attacker has full or partial control over redirect location due to an application bug, also known as an “Open Redirect”, they may inject arbitrary HTML into the response’s body, ultimately leading to an XSS attack.\n\nIt’s worth noting that the issue is known to maintainers and tracked with GitHub [Issue#9839](https://github.com/twisted/twisted/issues/9839). The issue description, however, does not make any mention of exploitability and simply states: “…Browsers don't seem to actually render that page…”\n\n### PoC\nThe issue can be reproduced by running the following Twisted-based HTTP server locally:\n```python\nfrom twisted.web import server, resource\nfrom twisted.internet import reactor\nfrom twisted.web.util import redirectTo\n\nclass Simple(resource.Resource):\n    isLeaf = True\n    def render_GET(self, request):\n        url = request.args[b'url'][0]  # <-- open redirect\n        return redirectTo(url, request)\n\nsite = server.Site(Simple())\nreactor.listenTCP(9009, site)\nreactor.run()\n```\nOnce running, navigate to the following URL: `http://127.0.0.1:9009?url=ws://example.com/\"><script>alert(document.location)</script>`, and verify that the “alert” dialog was displayed.\n\n**Note**: Due to the different ways browsers validate the redirect Location header, this attack is possible only in **Firefox**. All other tested browsers will display an error message to the user and will not render the HTML body.\n\n### Impact\nIf successfully exploited, the issue will allow malicious JavaScript to run in the context of the victim's session. This will in turn lead to unauthorized access/modification to victim's account and information associated with it, or allow for unauthorized operations to be performed within the context of the victim's session.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "twisted"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "24.7.0rc1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 24.3.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/security/advisories/GHSA-cf56-g6w6-pqq2"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-41810"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/commit/046a164f89a0f08d3239ecebd750360f8914df33"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/twisted/PYSEC-2024-75.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twisted/twisted"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/11/msg00028.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-07-29T17:29:36Z",
    "nvd_published_at" : "2024-07-29T16:15:05Z"
  }
}