CVE-2026-25048: xgrammar DoS Vulnerability via Multi-Layer Nesting
Summary
CVE-2026-25048: xgrammar vulnerable to DoS via multi-layer nesting. Affects xgrammar versions < 0.1.32. Fixed in 0.1.32. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
xgrammar is a Python library designed for efficient and flexible structured generation, particularly for tasks involving mathematical expression generation. It leverages advanced machine learning models to create complex outputs based on defined grammar rules. However, the library is susceptible to a denial-of-service (DoS) vulnerability due to its handling of deeply nested syntax, which can lead to significant resource exhaustion.
Vulnerability Detail
The vulnerability arises from the ability to create a malicious grammar rule that contains an excessive number of nested parentheses (up to 30,000 layers). This can trigger a stack overflow or memory exhaustion, resulting in a segmentation fault and crashing the application. The issue is rooted in the way xgrammar processes nested structures, making it vulnerable to crafted inputs that exploit this limitation.
How To Fix
Latest published version: 0.2.8 as of 23 Oct 2026
pip install --upgrade "xgrammar==0.2.8"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
0.1.32
This is the first release that contains the fix.
pip install --upgrade "xgrammar==0.1.32"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, avoid using deeply nested grammar rules in xgrammar. If you must use complex structures, limit the nesting to a safe level to prevent triggering the vulnerability.
Conclusion
The xgrammar library has a critical vulnerability (CVE-2026-25048) that can lead to denial-of-service attacks through excessive nesting in grammar rules. Users are advised to update to the latest version to mitigate this risk and to avoid deep nesting in the meantime.
See every vulnerability recorded for xgrammar →
FAQ
The vulnerability is a denial-of-service (DoS) issue caused by excessive multi-layer nesting in grammar rules, leading to segmentation faults.
You can use Vulert, which monitors open-source vulnerabilities in real-time. Visit the Vulert playground at Vulert Scanner to check your application without needing to sign up.
The CVSS score for this vulnerability is 8.7, indicating a high severity level.
If an immediate update is not possible, avoid using deeply nested grammar rules as a temporary measure to mitigate the risk.
You can find more information about xgrammar on its official repository or documentation pages, which provide insights into its features and usage.
References
Related vulnerabilities
Recent vulnerabilities recorded for xgrammar.