# CVE-2025-32381: Denial of Service by abusing xgrammar unbounded cache in memory

> An attacker can cause a denial of service by exhausting memory through unbounded caching of unique grammars in the XGrammar library.

- **Severity:** Medium 6.5 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 9 Apr 2025
- **Updated:** 9 Apr 2025
- **Also known as:** GHSA-389x-67px-mjg3, PYSEC-2025-235

## What is CVE-2025-32381?

CVE-2025-32381 is a medium-severity denial of service vulnerability in mlc-ai xgrammar, published on 9 Apr 2025. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

XGrammar is an open-source library for efficient, flexible, and portable structured generation. Prior to 0.1.18, Xgrammar includes a cache for compiled grammars to increase performance with repeated use of the same grammar. This cache is held in memory. Since the cache is unbounded, a system making use of xgrammar can be abused to fill up a host's memory and case a denial of service. For example, sending many small requests to an LLM inference server with unique JSON schemas would eventually cause this denial of service to occur. This vulnerability is fixed in 0.1.18.

Weakness: CWE-770 (Allocation of Resources Without Limits or Throttling)

## Which versions are affected by CVE-2025-32381?

3 open source packages ship an affected version, including xgrammar. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `xgrammar` | PyPI | All versions | 0.1.18 |
| `xgrammar` | PyPI | All versions | 0.1.18 |
| `xgrammar` | PyPI | All versions | 0.1.18 |

Products: Mlc-Ai Xgrammar.

## How do I fix CVE-2025-32381?

Upgrade xgrammar to 0.1.18 or later.

## Is CVE-2025-32381 being exploited?

There is no known exploitation of CVE-2025-32381 in the wild and no public exploit code.

## Other vulnerabilities in mlc-ai xgrammar

- [CVE-2026-25048](https://insights.sbomify.com/CVE-2026-25048/): xgrammar: Multi-layer nesting causes DoS (high 8.7)
- [CVE-2025-57809](https://insights.sbomify.com/CVE-2025-57809/): XGrammar affected by Denial of Service by infinite recursion grammars (high 7.7)
- [CVE-2025-58446](https://insights.sbomify.com/CVE-2025-58446/): xgrammar vulnerable to denial of service by huge enum grammar (medium 6.9)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-32381 and fix it if it is affected.

What it is: CVE-2025-32381 is a medium-severity denial of service vulnerability in mlc-ai xgrammar, published on 9 Apr 2025. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2025-32381 in the wild and no public exploit code.

Affected packages and fixed versions:
- xgrammar (PyPI): affected all versions; fixed in 0.1.18
- xgrammar (PyPI): affected all versions; fixed in 0.1.18
- xgrammar (PyPI): affected all versions; fixed in 0.1.18

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2025-32381/ (Markdown: https://insights.sbomify.com/CVE-2025-32381/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2025-32381
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2025-32381
- OSV: https://osv.dev/vulnerability/CVE-2025-32381

---
From sbomify Insights: https://insights.sbomify.com/CVE-2025-32381/
Summaries are generated and may contain mistakes; the official description above is the record.
