{"id":"CVE-2026-84305","aliases":["CVE-2026-84305","GHSA-cfqr-cjx5-5jcm","PYSEC-2026-3923"],"related":[],"kind":"vulnerability","state":"published","title":"sqlparse: Reindentation of tuple lists causes near-cap quadratic CPU consumption","summary":"sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, sqlparse.format(sql, reindent=True) and sqlformat --reindent route attacker-controlled parenthesized tuple lists through ReindentFilter._get_offset() in sqlparse/filters/reindent.py, where _flatten_up_to_token() repeatedly rebuilds and joins the statement prefix. Thousands of offset calculations walk an expanding token tree, producing quadratic CPU consumption for inputs that remain below MAX_GROUPING_TOKENS and causing request delays, reduced throughput, or worker starvation. This issue is fixed in version 0.6.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"sqlparse is a non-validating SQL parser module for Python. Prior to 0.6.0, sqlparse.format(sql, reindent=True) and sqlformat --reindent route attacker-controlled parenthesized tuple lists through ReindentFilter._get_offset() in sqlparse/filters/reindent.py, where _flatten_up_to_token() repeatedly rebuilds and joins the statement prefix. Thousands of offset calculations walk an expanding token tree, producing quadratic CPU consumption for inputs that remain below MAX_GROUPING_TOKENS and causing request delays, reduced throughput, or worker starvation. This issue is fixed in version 0.6.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nWhen SQL is formatted with reindentation enabled, `ReindentFilter` repeatedly rebuilds prefixes of the current statement to calculate token offsets. An attacker who controls SQL sent to this opt-in formatting path can supply a parenthesized tuple list that remains just below the grouping-token cap. Thousands of offset calculations then traverse an expanding token tree, causing multi-second CPU consumption from an input of roughly 16 KB and degrading service availability.\n\n### Details\n\n`ReindentFilter._get_offset()` joins the tokens returned by `_flatten_up_to_token()` to calculate the current output position. Each call begins by flattening the current statement from its start and walks until the target token. Tuple-list reindentation invokes this calculation repeatedly as it processes many parenthesized values, so later calls redo an increasingly large amount of prior work.\n\nThe vulnerable path is reached through `sqlparse.format(sql, reindent=True)` and `sqlformat --reindent`. A carefully sized tuple list completes grouping below the configured token cap and then enters the expensive reindentation path; a slightly larger input may instead be rejected quickly by the cap.\n\nRelevant code locations:\n\n- `sqlparse/formatter.py:170` — enabling `ReindentFilter`\n- `sqlparse/filters/reindent.py:30` — repeated flattening from the statement start\n- `sqlparse/filters/reindent.py:44` — prefix joining for offset calculation\n- `sqlparse/filters/reindent.py:216` — tuple-list processing path\n\n### PoC\n\nA complete validated reproduction is attached as [reindent_tuple_list_cpu_dos-poc.zip](https://github.com/user-attachments/files/29410152/reindent_tuple_list_cpu_dos-poc.zip). The archive contains `reproduction/` at its root, uses Git and Docker, and compares two same-shape tuple-list inputs formatted with reindentation enabled.\n\nExtract the archive beside this report, then run:\n\n```console\n./reproduction/run.sh\n```\n\nObserved result:\n\nThe 600-tuple baseline completed in 0.649 seconds, while the below-cap 1,425-tuple input completed in 4.999 seconds. The run emitted `EVOHUNT_REINDENT_DOS_VERIFIED` and completed successfully.\n\nVerification method:\n\nThe verification helper formats two same-shape tuple-list payloads with `reindent=True` and fails unless the larger payload completes successfully, takes at least 2.0 seconds, and takes at least 4x the baseline.\n\nLimitations:\n\nNo reproduction blocker was recorded. Timing varies by host, and exploitation requires the reindentation option or corresponding CLI mode to be enabled.\n\n### Impact\n\nThis is a CPU resource-exhaustion vulnerability in workflows that reindent attacker-controlled SQL. A small crafted tuple-list input can occupy a worker for several seconds, enabling request delays, reduced throughput, or worker starvation when payloads are processed repeatedly or concurrently.\n\nThe affected reindentation behavior is opt-in, and sqlparse itself does not provide network exposure; reachability depends on the consuming application or CLI workflow. The demonstrated effect is CPU consumption in a single formatting call, not process termination, code execution, or confidentiality or integrity impact.","format":"markdown","source":"ghsa"}],"published":"2026-09-01T18:33:10.969Z","modified":"2026-09-10T12:25:55.468Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":5.1,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":5.1,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"}],"cwes":["CWE-407"],"affected":[{"ranges":[{"version":"< 0.6.0","status":"affected"}],"vendor":"andialbrecht","product":"sqlparse","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.6.0"}],"ecosystem":"PyPI","package":"sqlparse","purl":"pkg:pypi/sqlparse","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.6.0"}],"ecosystem":"PyPI","package":"sqlparse","purl":"pkg:pypi/sqlparse","source":"pysec"}],"references":[{"url":"https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-cfqr-cjx5-5jcm","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/andialbrecht/sqlparse/commit/a51df6d9e2d31b44be9adb6bc8732517db6bf96b","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/andialbrecht/sqlparse/releases/tag/0.6.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/andialbrecht/sqlparse","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/sqlparse","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-cfqr-cjx5-5jcm","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-84305","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-09-01T19:12:32.847Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-84305","url":"https://www.cve.org/CVERecord?id=CVE-2026-84305","licence":"CVE Terms of Use","modified":"2026-09-01T19:12:52.039Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-cfqr-cjx5-5jcm","url":"https://github.com/advisories/GHSA-cfqr-cjx5-5jcm","licence":"CC-BY-4.0","modified":"2026-09-10T12:25:55.468Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-84305","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-84305","licence":"Public domain","modified":"2026-09-09T21:09:13.080Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-3923","url":"https://osv.dev/vulnerability/PYSEC-2026-3923","licence":"CC-BY-4.0","modified":"2026-09-10T12:15:12.861Z"}],"updatedAt":"2026-11-25T22:59:35.992Z","epss":{"score":0.00189,"percentile":0.08928,"date":"2026-12-01T12:00:22.000Z"}}