CVE-2026-53540: python-multipart Negative Content-Length Vulnerability

LOW
Advisory Identifier: GHSA-v9pg-7xvm-68hf
CVSS 3.7
CWE-1284
Published
Advisory Summary

CVE-2026-53540 is a LOW (CVSS 3.7) negative content-length vulnerability (CWE-1284: Improper Validation of Specified Quantity in Input) affecting python-multipart libraries in the PyPI ecosystem. The issue involves negative content-length in parse_form buffers the entire body in memory. Remediation is available by upgrading affected packages to version 0.0.31.

CVE-2026-53540 at a Glance

CVE Identifier CVE-2026-53540
GHSA Identifier GHSA-v9pg-7xvm-68hf
Severity LOW
CVSS v3.1 Base Score 3.7
CWE Classification CWE-1284: Improper Validation of Specified Quantity in Input
Affected Product python-multipart
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 3.7

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L).

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

How to Fix CVE-2026-53540

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

python-multipart fixed: 0.0.31
pip install python-multipart>=0.0.31
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 python-multipart

How to Check if You Are Affected

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

pip show python-multipart

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1284: Improper Validation of Specified Quantity in Input, where the product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties. In python-multipart, 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 `parse_form()` did not validate the `Content-Length` header before using it to bound its chunked read of the request body. A negative `Content-Length` turned the bounded read into a read-until-EOF, so the entire body was loaded into memory in a single read instead of in fixed-size chunks. ### Details `parse_form()` reads the input stream in chunks, never reading more than the remaining `Content-Length` at a time. The per-chunk size is computed as `min(content_length - bytes_read, chunk_size)`. The header value was parsed to an integer without checking its sign, so a `Content-Length` of `-1` made this expression negative, and `input_stream.read(-1)` reads until end of stream. The intended bounded, chunked read therefore collapsed into a single unbounded read of the whole stream. The amount read is still bounded by what the client actually sends. ### Impact This only affects code that calls `parse_form()` directly with a `Content-Length` header taken from attacker-controlled input and without normalizing a negative value first. No known package is affected: * Starlette and FastAPI drive `MultipartParser` directly from the ASGI `receive()` stream and do not call `parse_form()`. * Known `parse_form()` consumers either do not forward `Content-Length` to it, recompute it from the already-read body, or run behind a layer (such as Werkzeug) that normalizes a negative `Content-Length` to `0`. The realistic exposure is limited to bespoke WSGI or `http.server` handlers that forward raw client headers into `parse_form()`. In that case a crafted request buffers the body in memory at once, degrading availability under concurrent requests rather than causing a complete denial of service. ### Mitigation Upgrade to version `0.0.31` or later, which rejects a negative `Content-Length` with a `ValueError` before reading the stream.

CVE-2026-53540 Affected python-multipart Versions

1 component(s)
Fixed Versions:
0.0.31
Product / Package Ecosystem Affected Versions Fixed Version
python-multipart
PyPI
< 0.0.31
0.0.31

References

Frequently Asked Questions

What is CVE-2026-53540?
CVE-2026-53540 is a security vulnerability in python-multipart involving Negative Content-Length in parse_form buffers the entire body in memory under CWE-1284: Improper Validation of Specified Quantity in Input.
Which python-multipart versions are affected?
Affected versions include releases prior to 0.0.31 across affected packages: python-multipart.
What version fixes CVE-2026-53540?
Upgrading to 0.0.31 (or the latest patched release for your respective branch) resolves the vulnerability.
Is python-multipart affected?
Yes, python-multipart is affected in releases prior to 0.0.31. Upgrade your dependency to 0.0.31 or later.
What is the CVSS score of CVE-2026-53540?
CVE-2026-53540 has a CVSS v3.1 base score of 3.7 (LOW) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L.
What CWE is associated with CVE-2026-53540?
CVE-2026-53540 is classified under CWE-1284: Improper Validation of Specified Quantity in Input (The product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties.).
How can I check PyPI dependencies for CVE-2026-53540?
Run the dependency tree command: 'pip show python-multipart'. 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-v9pg-7xvm-68hf",
  "modified" : "2026-06-15T20:23:45Z",
  "published" : "2026-06-15T20:23:45Z",
  "aliases" : [ "CVE-2026-53540" ],
  "summary" : "python-multipart: Negative Content-Length in parse_form buffers the entire body in memory",
  "details" : "### Summary\n\n`parse_form()` did not validate the `Content-Length` header before using it to bound its chunked read of the request body. A negative `Content-Length` turned the bounded read into a read-until-EOF, so the entire body was loaded into memory in a single read instead of in fixed-size chunks.\n\n### Details\n\n`parse_form()` reads the input stream in chunks, never reading more than the remaining `Content-Length` at a time. The per-chunk size is computed as `min(content_length - bytes_read, chunk_size)`. The header value was parsed to an integer without checking its sign, so a `Content-Length` of `-1` made this expression negative, and `input_stream.read(-1)` reads until end of stream. The intended bounded, chunked read therefore collapsed into a single unbounded read of the whole stream. The amount read is still bounded by what the client actually sends.\n\n### Impact\n\nThis only affects code that calls `parse_form()` directly with a `Content-Length` header taken from attacker-controlled input and without normalizing a negative value first. No known package is affected:\n\n* Starlette and FastAPI drive `MultipartParser` directly from the ASGI `receive()` stream and do not call `parse_form()`.\n* Known `parse_form()` consumers either do not forward `Content-Length` to it, recompute it from the already-read body, or run behind a layer (such as Werkzeug) that normalizes a negative `Content-Length` to `0`.\n\nThe realistic exposure is limited to bespoke WSGI or `http.server` handlers that forward raw client headers into `parse_form()`. In that case a crafted request buffers the body in memory at once, degrading availability under concurrent requests rather than causing a complete denial of service.\n\n### Mitigation\n\nUpgrade to version `0.0.31` or later, which rejects a negative `Content-Length` with a `ValueError` before reading the stream.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "python-multipart"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.0.31"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Kludex/python-multipart/security/advisories/GHSA-v9pg-7xvm-68hf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Kludex/python-multipart"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1284" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-15T20:23:45Z",
    "nvd_published_at" : null
  }
}