Skip to main content
Vulnerability Database/CVE-2026-76875

CVE-2026-76875: PyPy Use-After-Free Vulnerability

CVE-2026-76875 is a use-after-free flaw in PyPy's pyexpat module affecting XML parsing. Attackers can exploit this to corrupt memory through crafted XML documents. This article covers technical details, affected versions, and mitigation.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-76875 Overview

CVE-2026-76875 is a use-after-free vulnerability [CWE-416] in PyPy's pyexpat module. The flaw resides in the ExternalEntityParserCreate function within the bundled libexpat integration. PyPy versions prior to 3.11.16 and 3.12.14 are affected. Attackers can trigger memory corruption by delivering a crafted XML document to applications that create external-entity sub-parsers without holding a reference to the parent parser. The child parser retains a raw C back-pointer to the parent, while PyPy's tracing garbage collector can free the parent's C struct independently. The bundled libexpat then dereferences the freed pointer on each parsed token.

Critical Impact

Memory corruption in PyPy applications parsing untrusted XML with external entity sub-parsers, potentially leading to process instability or exploitation of freed heap memory.

Affected Products

  • PyPy versions prior to 3.11.16
  • PyPy versions prior to 3.12.14
  • Applications embedding PyPy's pyexpat module with bundled libexpat

Discovery Timeline

  • 2026-09-29 - CVE-2026-76875 published to NVD
  • 2026-09-29 - Last updated in NVD database

Technical Details for CVE-2026-76875

Vulnerability Analysis

The vulnerability originates in the interaction between PyPy's tracing garbage collector and the C-level object lifetime model used by the bundled libexpat library. When an application calls ExternalEntityParserCreate on a parent xmlparser object, PyPy creates a child parser that holds a raw C back-pointer to the parent parser struct. This back-pointer bypasses the Python object graph that PyPy's garbage collector tracks.

If the calling code does not retain a Python-level reference to the parent parser, the garbage collector treats the parent as unreachable. PyPy frees the underlying C struct while the child parser still references it. Each subsequent token parsed by libexpat dereferences the freed memory, producing memory corruption in the process heap.

The vulnerability requires an application-level pattern where external entity sub-parsers are created without parent retention, combined with attacker-supplied XML content.

Root Cause

The root cause is a lifetime mismatch between PyPy's tracing garbage collector and the C-level ownership contract of libexpat. The child parser holds a non-tracked C pointer to the parent parser struct. PyPy's collector has no visibility into this dependency and reclaims the parent when no Python reference exists. CPython's reference-counting model does not exhibit this behavior because parent lifetime is bound by explicit reference counts.

Attack Vector

Exploitation requires an attacker to submit a crafted XML document to a PyPy application that parses XML using pyexpat and creates external entity sub-parsers without retaining the parent reference. The attack is network-reachable when the vulnerable application accepts XML from remote sources, such as web services, RPC endpoints, or document processors. Successful exploitation produces heap memory corruption during token parsing. The vulnerability does not require authentication or user interaction beyond XML submission. See the VulnCheck Advisory: PyPy Use-After-Free for additional technical detail.

Detection Methods for CVE-2026-76875

Indicators of Compromise

  • Unexpected crashes or segmentation faults in PyPy processes handling XML input
  • Heap corruption signatures in process core dumps referencing libexpat or pyexpat frames
  • Anomalous XML documents containing external entity declarations submitted to PyPy-based services

Detection Strategies

  • Inventory PyPy interpreters across build systems and production hosts and identify versions prior to 3.11.16 and 3.12.14
  • Scan application source for calls to xml.parsers.expat.ParserCreate followed by ExternalEntityParserCreate without explicit parent retention
  • Monitor process telemetry for repeated PyPy crashes correlated with inbound XML traffic

Monitoring Recommendations

  • Alert on unexpected termination of PyPy worker processes in web application and API tiers
  • Log XML payloads that reference external entities at ingress boundaries for post-incident analysis
  • Track deployment of PyPy runtime versions through configuration management inventory

How to Mitigate CVE-2026-76875

Immediate Actions Required

  • Upgrade PyPy installations to 3.11.16, 3.12.14, or later
  • Audit application code for ExternalEntityParserCreate usage and ensure parent parser references are retained for the lifetime of any child parser
  • Disable external entity resolution in XML parsers that process untrusted input where feasible

Patch Information

PyPy addressed the vulnerability in the 8.0.0 release series. Fixed versions are 3.11.16 and 3.12.14. Refer to the PyPy 8.0.0 Release Documentation, the GitHub Release: PyPy 3.11 v8.0.0, and the GitHub Release: PyPy 3.12 v8.0.0 for full release details.

Workarounds

  • Retain a Python-level reference to the parent parser for the full lifetime of any child parser created via ExternalEntityParserCreate
  • Disable external entity processing in XML input paths where the feature is not required
  • Route XML processing through CPython interpreters until PyPy runtime upgrades are complete
  • Restrict network exposure of PyPy services that parse XML from untrusted sources
bash
# Verify installed PyPy version
pypy3 --version

# Example pip-based upgrade (adjust to your distribution channel)
pypy3 -m pip install --upgrade pip

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.