CVE-2025-58446: xgrammar Denial of Service Vulnerability Due to Slow Grammar Optimization
Summary
CVE-2025-58446: xgrammar vulnerable to denial of service by huge enum grammar. Affects xgrammar versions >= 0.1.23, < 0.1.24. Fixed in 0.1.24. 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 package designed for parsing and processing grammars, particularly in the context of language models. It offers functionalities that allow users to define and manipulate complex grammar structures. However, a recent update introduced performance issues that can lead to denial of service (DoS) when handling large grammars, making it crucial for users to be aware of this vulnerability.
Vulnerability Detail
The vulnerability arises from a regression in the grammar optimizer introduced in version 0.1.23 of xgrammar. This optimizer is significantly slower when processing large grammars (over 100k characters), causing the parsing process to take an excessive amount of time. As a result, this can be exploited to perform denial of service attacks against model providers, as the parsing time can exceed the time taken by the models themselves. The issue was not present in earlier versions, such as 0.1.16, indicating that the problem is specifically linked to the changes made in the newer version.
How To Fix
Minimum fixed version
0.1.24
This is the first release that contains the fix.
pip install --upgrade "xgrammar==0.1.24"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If immediate upgrading is not possible, users can avoid using large grammars (over 100k characters) until the package is updated. Additionally, users can implement their own optimizations or limit the size of the input grammars to mitigate the impact of this vulnerability.
Conclusion
The xgrammar package has a vulnerability (CVE-2025-58446) that can lead to denial of service when processing large grammars due to slow optimization in version 0.1.23. Users are advised to upgrade to version 0.1.24 or later to mitigate this issue. Temporary workarounds include avoiding large grammars until the update is applied.
See every vulnerability recorded for xgrammar →
FAQ
CVE-2025-58446 is a vulnerability in the xgrammar package that can lead to denial of service due to slow grammar processing in version 0.1.23.
If your application uses xgrammar version 0.1.23 or earlier and processes large grammars, it may experience significant delays or become unresponsive, leading to potential denial of service.
As a temporary measure, avoid using large grammars or implement your own optimizations to reduce the size of the input grammars.
You can find detailed information about CVE-2025-58446 in the advisory database on GitHub or by visiting Vulert, which monitors open-source vulnerabilities.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.
References
Related vulnerabilities
Recent vulnerabilities recorded for xgrammar.