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-2025-32381 Overview
CVE-2025-32381 affects XGrammar, an open-source library for efficient, flexible, and portable structured generation used in large language model (LLM) inference pipelines. Versions prior to 0.1.18 maintain an unbounded in-memory cache for compiled grammars. An authenticated attacker can send many small requests with unique JSON schemas to an LLM inference server that uses XGrammar, exhausting host memory and triggering a denial of service. The maintainers fixed the issue in version 0.1.18. The vulnerability is tracked as CWE-770: Allocation of Resources Without Limits or Throttling.
Critical Impact
Attackers with network access to an LLM inference endpoint using XGrammar can exhaust host memory by submitting many unique grammars, degrading or disabling the service.
Affected Products
- mlc-ai XGrammar versions prior to 0.1.18
- LLM inference servers embedding XGrammar for structured output (for example, vLLM integrations)
- Any application relying on XGrammar's compiled grammar cache for JSON schema or grammar-constrained generation
Discovery Timeline
- 2025-04-09 - CVE-2025-32381 published to the National Vulnerability Database (NVD)
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2025-32381
Vulnerability Analysis
XGrammar compiles grammars (including JSON schemas) into an internal representation to accelerate repeated structured generation requests. To avoid recompiling the same grammar, the library caches compiled artifacts in process memory. Prior to version 0.1.18, this cache had no size limit, no eviction policy, and no admission controls. Every unique grammar submitted to the library produced a new cache entry that persisted for the lifetime of the process.
Because LLM inference servers commonly accept user-supplied schemas for constrained decoding, this behavior creates a direct path from untrusted input to unbounded server-side allocation. An attacker submits a stream of requests, each with a slightly different JSON schema, causing continuous growth of the cache. The process eventually consumes all available memory and is terminated by the operating system or the container runtime.
Root Cause
The root cause is the absence of resource limits on the compiled grammar cache. The cache stored entries keyed by grammar content without a maximum entry count, memory ceiling, or least-recently-used eviction. Any input surface that reached the cache function inherited the unbounded behavior. This maps to CWE-770.
Attack Vector
The attack requires network access and low privileges typical of an authenticated API consumer of an LLM inference server. No user interaction is required. The attacker iterates through unique schemas or grammars, submitting them as parameters to inference requests. Because each grammar is small, the attack is bandwidth-efficient while producing amplified server-side memory pressure. The impact is limited to availability; confidentiality and integrity are not affected.
For technical details on the fix, see the XGrammar security advisory GHSA-389x-67px-mjg3, the upstream patch in pull request #243, and the vLLM integration change in pull request #16283.
Detection Methods for CVE-2025-32381
Indicators of Compromise
- Sustained growth in resident set size (RSS) of inference server processes without a corresponding increase in concurrent inference sessions.
- High volume of requests from a single client or token containing distinct JSON schemas or grammar strings.
- Out-of-memory (OOM) kills, container restarts, or pod evictions on hosts running XGrammar-backed inference services.
Detection Strategies
- Instrument the inference API to log the hash of each submitted grammar or JSON schema and alert on abnormally high unique-schema rates per client.
- Track XGrammar cache size metrics if exposed by the host application and alert on unbounded growth.
- Correlate API request logs with process memory telemetry to identify clients whose requests precede memory spikes.
Monitoring Recommendations
- Add Prometheus or equivalent metrics for process memory, cache entry counts, and per-client schema diversity.
- Enable rate limiting and structured logging at the API gateway to attribute schema submissions to authenticated identities.
- Configure alerts on repeated OOM events for inference workloads and correlate them with recent client activity.
How to Mitigate CVE-2025-32381
Immediate Actions Required
- Upgrade XGrammar to version 0.1.18 or later across all inference hosts and container images.
- Update downstream projects such as vLLM to versions that pull in the fixed XGrammar release.
- Apply per-client rate limits and quotas on requests that carry user-supplied JSON schemas or grammars.
- Restrict which authenticated principals may submit arbitrary grammars; require least privilege on inference endpoints.
Patch Information
The vulnerability is fixed in XGrammar 0.1.18. The upstream fix is documented in pull request #243 and the GitHub Security Advisory GHSA-389x-67px-mjg3. Downstream integrations such as vLLM adopted the fix in pull request #16283. Rebuild container images to ensure the pinned version reflects 0.1.18 or later.
Workarounds
- Restart inference workers on a schedule to bound cache growth until patching is complete.
- Set container memory limits so that OOM-kill isolates a single worker rather than affecting the host.
- Reject requests containing grammars or schemas above a defined size or complexity threshold at the API gateway.
- Deploy an allowlist of pre-approved schemas for production workloads instead of accepting arbitrary client input.
# Configuration example: pin the fixed XGrammar version
pip install --upgrade 'xgrammar>=0.1.18'
# Verify installed version
python -c "import xgrammar; print(xgrammar.__version__)"
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

