CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-84305

CVE-2026-84305: Algorithmic Complexity Vulnerability (ReindentFilter CPU Exhaustion) in sqlparse

Amit Schendel
Amit Schendel
Senior Security Researcher

Sep 2, 2026·6 min read·59 visits

Executive Summary (TL;DR)

The sqlparse library contains an O(N^2) complexity flaw in its reindentation filter, allowing small crafted SQL payloads to trigger CPU exhaustion and denial of service.

An algorithmic complexity vulnerability in the python sqlparse library versions before 0.6.0 allows an attacker to cause high CPU usage and denial of service via a crafted SQL statement during formatting.

Vulnerability Overview

The non-validating SQL parser library for Python, sqlparse, provides features for tokenizing, parsing, and formatting SQL statements. The vulnerability resides within the formatting module, specifically affecting the ReindentFilter class which manages token alignment and indentation. When formatting is performed with the reindentation flag enabled, the parser calculates indentation offsets dynamically for each SQL token group.\n\nAn attack surface is exposed in applications that accept user-defined SQL statements and format them before logging, displaying, or processing them further. This is a common pattern in database management interfaces, web-based SQL beautifiers, and query-logging systems. By supplying a crafted SQL input, an attacker can exploit an inefficient algorithm in the formatting step to cause a denial of service.\n\nThe vulnerability is classified under CWE-407 (Inefficient Algorithmic Complexity). It exhibits quadratic $O(N^2)$ time complexity when processing structures with numerous parallel tuple sequences. This behavior allows relatively small payloads to exhaust CPU resources on the target system.

Root Cause Analysis

The core issue exists in how the ReindentFilter calculates the column offset for any given token during formatting. To compute this offset, the filter calls the internal _get_offset(self, token) method, which determines the length of the string emitted on the current line prior to the token. In versions before 0.6.0, this calculation relied on a helper method named _flatten_up_to_token(self, token).\n\nThe _flatten_up_to_token() method performs a forward traversal of the parsed Abstract Syntax Tree (AST), starting from the very first token in the statement (self._curr_stmt) up to the target token. After yielding all preceding tokens, the filter joins them into a single string to measure the characters on the active line. This layout requires a complete reconstruction of the preceding SQL string for every call to _get_offset().\n\nWhen a SQL query contains a large number of tuple lists, such as thousands of elements within an IN clause or an INSERT INTO ... VALUES statement, _get_offset() is executed once for each group. For $N$ parenthesized groups, the system performs a sequence of string building operations proportional to $1 + 2 + \dots + N$, resulting in $O(N^2)$ quadratic complexity. While sqlparse implements a limit of MAX_GROUPING_TOKENS = 10000 to prevent deep recursion, a flat array of tuples bypasses this threshold, permitting execution of the vulnerable formatting routine.

Code Analysis

A review of the vulnerable implementation in sqlparse/filters/reindent.py highlights the inefficient forward traversal mechanism. The helper method _flatten_up_to_token() flattens the syntax tree starting from the root of the parsed structure for every offset evaluation:\n\npython\n# Vulnerable implementation in sqlparse < 0.6.0\ndef _flatten_up_to_token(self, token):\n \"\"\"Yields all tokens up to token but excluding current.\"\"\"\n if token.is_group:\n token = next(token.flatten())\n\n for t in self._curr_stmt.flatten():\n if t == token:\n break\n yield t\n\ndef _get_offset(self, token):\n raw = ''.join(map(str, self._flatten_up_to_token(token)))\n line = (raw or '\\n').splitlines()[-1]\n return len(line) - len(self.char * self.leading_ws)\n\n\nThe patch introduced in version 0.6.0 (commit a51df6d9e2d31b44be9adb6bc8732517db6bf96b) completely eliminates _flatten_up_to_token(). It introduces _current_line_len(), which performs a backward traversal from the current token. It navigates backwards through parent and sibling nodes, accumulating character counts and halting immediately upon encountering a newline character:\n\npython\n# Patched implementation in sqlparse >= 0.6.0\ndef _current_line_len(self, token):\n length = 0\n node = token\n while node is not self._curr_stmt and node.parent is not None:\n parent = node.parent\n stack = parent.tokens[:parent.tokens.index(node)]\n while stack:\n prev_ = stack.pop()\n if prev_.is_group:\n stack.extend(prev_.tokens)\n continue\n value = prev_.value\n size = len(value)\n if not size:\n continue\n lines = value.splitlines()\n if len(lines) == 1 and len(lines[0]) == size:\n length += size\n continue\n lines = (value + '.').splitlines()\n tail = len(lines[-1]) - 1 + length\n if tail:\n return tail\n if len(lines) > 2:\n return len(lines[-2])\n length = len(lines[0])\n node = parent\n return length\n\n\nThis remediation successfully reduces the computational complexity of determining the offset from $O(\text{statement\_length})$ to $O(\text{line\_length})$. Since SQL lines are naturally bounded by design, the lookup executes in nearly constant time, rendering the overall formatting operation linear $O(N)$.

Exploitation Methodology

Exploitation of this vulnerability requires an application configuration that formats user-controlled SQL input with the opt-in reindent=True parameter. An attacker can construct a payload consisting of a large, flat collection of tuple elements. This structure is intentionally designed to remain below the default security limit of 10,000 grouping tokens, ensuring that the initial parsing phase completes without exception.\n\nmermaid\ngraph LR\n A[\"Crafted Payload (~12 KB SQL)\"] --> B[\"sqlparse.format(reindent=True)\"]\n B --> C[\"ReindentFilter processes token groups\"]\n C --> D[\"Quadratic complexity in _get_offset()\"]\n D --> E[\"100% CPU exhaustion on worker thread\"]\n\n\nTo execute the attack, a payload containing approximately 1,500 tuples is sent to the target endpoint. Each tuple increases the overall prefix length that the vulnerable version must reconstruct. As the formatting engine handles each sequential group, the computational overhead escalates. This results in CPU starvation for the active application thread.\n\nThe benchmark code demonstrates that doubling the size of the tuple array causes a four-fold increase in execution time. While a normal SQL query of standard size formats in milliseconds, a 12 KB payload can pin a modern CPU core for several seconds, leading to thread exhaustion if multiple requests are processed simultaneously.

Impact Assessment

The primary impact of CVE-2026-84305 is application-level denial of service. When a vulnerable instance processes a crafted SQL statement, the executing worker thread is blocked entirely while computing token offsets. In single-threaded runtime environments, this action halts the entire application process, preventing all other concurrent requests from being served.\n\nIn multi-threaded or multi-process architectures, an attacker can launch concurrent requests containing the payload to consume all available worker slots. Once the thread pool is fully utilized, the application server stops responding to legitimate traffic. This can trigger health check failures, causing automated load balancers to terminate and restart the containers, compounding the service disruption.\n\nThis vulnerability is assigned a CVSS v4.0 score of 5.1, reflecting a medium-severity local or remote threat with low operational complexity. There is no risk of confidentiality loss, data integrity compromise, or privilege escalation. The scope of impact is restricted strictly to resource exhaustion and system availability.

Remediation and Mitigation

The primary remediation step is upgrading the sqlparse package to version 0.6.0 or higher. This release contains the updated backward-traversal algorithm that resolves the algorithmic complexity flaw. Security teams should verify dependencies in project requirements files and execute the package update.\n\nIf immediate upgrade is not feasible, a temporary workaround consists of disabling the reindent formatting flag in application code. Developers should review all invocations of sqlparse.format() and ensure that reindent is set to False when processing input from untrusted sources. This action bypasses the vulnerable ReindentFilter execution path completely.\n\npython\n# Vulnerable pattern\nformatted_query = sqlparse.format(user_input, reindent=True)\n\n# Mitigated pattern\nformatted_query = sqlparse.format(user_input, reindent=False)\n\n\nThe fix implemented in version 0.6.0 is complete and robust. By switching from a full prefix-rebuilding forward scan to a localized backward scan bounded by newline characters, the library avoids calculating offset information for irrelevant lines. This algorithmic improvement permanently eliminates the quadratic behavior without reducing the functionality of the formatting system.

Fix Analysis (1)

Technical Appendix

CVSS Score
5.1/ 10
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

Affected Systems

sqlparse (Python package)

Affected Versions Detail

Product
Affected Versions
Fixed Version
sqlparse
andialbrecht
< 0.6.00.6.0
AttributeDetail
CWE IDCWE-407
Attack VectorLocal / Remote (via untrusted SQL input formatting)
CVSS v4.0 Score5.1
Exploit MaturityProof-of-Concept
KEV StatusNot Listed
Ransomware AssociationNo

MITRE ATT&CK Mapping

T1499.004Endpoint Denial of Service: Application Exhaustion
Impact
CWE-407
Inefficient Algorithmic Complexity

The product uses an algorithm with an inefficient worst-case time complexity that can be exploited by an attacker to cause a denial of service.

References & Sources

  • [1]GitHub Security Advisory GHSA-cfqr-cjx5-5jcm
  • [2]Fix Commit a51df6d9e2d31b44be9adb6bc8732517db6bf96b
  • [3]sqlparse 0.6.0 Release Notes
  • [4]CVE.org Record
  • [5]NVD Vulnerability Detail

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•2 minutes ago•CVE-2026-114132
6.3

CVE-2026-114132: Case-Sensitivity Route Rule Bypass in Nuxt Framework

Nuxt versions prior to 4.6.2 suffer from a route rule bypass vulnerability caused by an architectural mismatch in case-sensitivity handling between the Nitro server runtime and the Vue page router. An unauthenticated remote attacker can bypass server-enforced route directives—such as redirects, security headers, and SSR controls—by altering character casing in HTTP request paths.

Amit Schendel
Amit Schendel
0 views•6 min read
•about 1 hour ago•GHSA-78G4-XQWV-Q3G8
7.5

GHSA-78G4-XQWV-Q3G8: Heap-Based Buffer Overflow in Pillow (libopenjp2)

A heap-based buffer overflow vulnerability in Pillow PyPI binary wheels (versions 11.1.0 to 12.x) allows remote code execution or application crash via crafted JPEG 2000 files processed by the bundled libopenjp2 library.

Alon Barad
Alon Barad
13 views•4 min read
•about 2 hours ago•CVE-2026-109618
9.8

CVE-2026-109618: Remote Code Execution in PHP Core via Out-of-Memory longjmp() Uninitialized Memory Access

CVE-2026-109618 (dubbed PHP2Shell) is a critical vulnerability in the PHP engine core resulting from improper out-of-memory exception handling via longjmp(). When request allocation fails mid-processing, non-local control flow bypasses cleanup procedures, leaving memory structures uninitialized or in a use-after-free state during request shutdown.

Amit Schendel
Amit Schendel
9 views•5 min read
•about 2 hours ago•CVE-2026-109619
9.2

CVE-2026-109619: Remote Code Execution in PHP Core via Stale Global State Memory Corruption (PHP2Shell)

CVE-2026-109619 (PHP2Shell) is a critical Use-After-Free vulnerability in the core PHP engine caused by improper global state cleanup during out-of-memory exception handling across persistent worker requests.

Alon Barad
Alon Barad
10 views•6 min read
•about 2 hours ago•CVE-2026-113721
4.5

CVE-2026-113721: Unsafe Link Resolution in virtualenv File Generation

In Python virtualenv prior to version 21.14.9, activation script generators and configuration writers use Path.exists() before writing files. Because Path.exists() resolves symbolic links, it returns False for dangling symlinks. Consequently, virtualenv skips unlinking pre-planted symbolic links or hard links, writing data directly to target locations outside the intended virtual environment directory.

Amit Schendel
Amit Schendel
3 views•5 min read
•10 days ago•CVE-2026-87697
8.8

CVE-2026-87697: Untrusted Deserialization in .NET PresentationCore Clipboard Handling

A remote code execution vulnerability exists in Microsoft .NET due to untrusted data deserialization within the PresentationCore component. The flaw stems from implicit auto-conversion flags during clipboard data retrieval operations.

Alon Barad
Alon Barad
31 views•5 min read