PyPI: xgrammar

CVE-2026-25048

Safety vulnerability ID: SFTY-20260305-47265

Safety legacy ID: pyup.io-88435

Affected versions of the xgrammar package are vulnerable to Denial of Service (DoS) due to uncontrolled recursion and resource consumption when parsing deeply nested grammar rules. The vulnerability exists in GrammarCompiler.compile_grammar, which processes attacker-supplied grammar definitions and can be driven into a stack overflow or memory exhaustion by a malicious rule containing approximately 30,000 layers of nested parentheses.

Created at: Mar 13, 2026Updated at: Mar 13, 2026

Overview

xgrammar vulnerable to DoS via multi-layer nesting

Advisory

Affected versions of the xgrammar package are vulnerable to Denial of Service (DoS) due to uncontrolled recursion and resource consumption when parsing deeply nested grammar rules. The vulnerability exists in GrammarCompiler.compile_grammar, which processes attacker-supplied grammar definitions and can be driven into a stack overflow or memory exhaustion by a malicious rule containing approximately 30,000 layers of nested parentheses.

Affected Package

Affecting xgrammar package, versions
<0.1.32

Also affects

---

How to Fix

Upgrade
xgrammar
to
0.1.32
or higher.

Mitigation and Workarounds

---

Vulnerable Functions

Functions linked to known vulnerabilities.

Vulnerable function data is available for Enterprise customers

Book a call with us to see Safety in action.

Safety

Verified by Safety

Our Cybersecurity Intelligence Team reviewed this vulnerability. We combine public data with our own research to find issues not yet reported to public sources.

Learn more