已关闭
CVE-2026-59893 #10
openeuler-ci-bot创建于  12 天前关闭于  9 天前
openeuler-ci-bot
openeuler-ci-bot成员
12 天前 创建

一、漏洞信息
漏洞编号:CVE-2026-59893
漏洞归属组件:python-sqlparse
漏洞归属的版本:0.3.1,0.4.1,0.4.2,0.4.3,0.4.4,0.5.1,0.5.5
CVSS评分:
BaseScore:7.5 High
Vector:CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
漏洞简述:

Summarysqlparse 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 Additional affected pattern: multiline comments below.### DetailsThe vulnerable regex is defined in sqlparse/keywords.py as part of SQL_REGEX:python# sqlparse/keywords.py:33(r ((?<![ w $]) $(?:[_A-ZÀ-Ü] w*)? $)[ s S]*? 1 , 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-138for 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:20parse(sql) accepts caller-controlled SQL.2. sqlparse/__init__.py:29 — delegates to parsestream(sql, encoding).3. sqlparse/__init__.py:43FilterStack.run(stream, encoding) is invoked.4. sqlparse/engine/filter_stack.py:31lexer.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.### PoCPrerequisites: 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 accessdocker run --rm --network=none sqlparse-vuln001Direct Python reproduction:pythonimport timeimport sqlparsefrom sqlparse.exceptions import SQLParseErrordef make_payload(n: int) -> str: # N unique unmatched dollar-quote openers — none have a matching closing delimiter return .join(f $a{i}$x 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 = ok except SQLParseError as e: status = f SQLParseError: {e} elapsed = time.perf_counter() - t0 print(f n={n:>5} bytes={len(payload):>7} elapsed={elapsed:.3f}s status={status} )Expected output (super-linear scaling confirms ReDoS):n= 250 bytes= 1889 elapsed=0.066s status=okn= 500 bytes= 3889 elapsed=0.144s status=okn= 1000 bytes= 7889 elapsed=0.397s status=okn= 2000 bytes= 16889 elapsed=1.314s status=okKey ratio (n=1000 -> n=2000): 3.31x[PASS] Super-linear (O(n^2)) scaling CONFIRMED.Attack input structure:$a0$x $a1$x $a2$x ... $a{N-1}$xEach token $ai$x resembles a PostgreSQL-style dollar-quote opening tag. Because every tag is unique and no closing tag is present, the regex engine must scan to the end of the string for each opener before backtracking.**Remediation (proposed patch)😗*Replace the backreference regex with a deterministic two-pass approach: first locate all delimiter positions with re.finditer, then resolve open/close pairs in O(n) time, eliminating catastrophic backtracking entirely. See report_excerpt.md for the full diff.### Additional affected pattern: multiline commentsReported independently as GHSA-3crh-2448-7855 (by @7thParkk) and merged into this advisory: it is the same defect class in the same lexer loop, and it is addressed by the same fix.Two further entries in SQL_REGEX use the same lazy dot-all shape, terminated by a literal delimiter instead of a backreference:python# sqlparse/keywords.py:20(r / * +[ s S]*? */ , tokens.Comment.Multiline.Hint),# sqlparse/keywords.py:23(r / *[ s S]*? */ , tokens.Comment.Multiline),A backreference is not required to trigger the quadratic behaviour. The cost comes from the lexer retrying every pattern at every input position (sqlparse/lexer.py:136-138): an unterminated /* scans to the end of the input and fails, so N unclosed openers cost O(N²).PoCpythonimport time, sqlparsefor n in (2000, 4000, 8000, 16000): payload = /*x * n t0 = time.perf_counter() sqlparse.parse(payload) print(f n={n:6d} bytes={len(payload):7d} elapsed={time.perf_counter()-t0:.3f}s )Lexing-only timings on 0.5.6.dev0 (commit f80af6a), isolating the regex work from grouping:| openers | bytes | lexing ||---------|-------|--------|| 2,000 | 8 KB | 0.057 s || 4,000 | 16 KB | 0.196 s || 8,000 | 32 KB | 0.729 s || 16,000 | 64 KB | 2.717 s |Roughly 3.7x per doubling of the input, i.e. quadratic.Note for reproduction: /* * n on its own is linear and does not reproduce the issue — in /*/*/*... the openers form overlapping */ pairs, so the pattern matches immediately. The opener must be padded (e.g. /*x ) so that it never closes. A reproduction that only tries the unpadded form will wrongly conclude the issue is not present.### ImpactThis is a Regular Expression Denial of Service (ReDoS) vulnerability. Any application or service that passes user-controlled SQL text to sqlparse.parse(), sqlparse.format(), or sqlparse.split() is affected. No authentication, special configuration, or elevated privileges are required — a single crafted HTTP request (or any other input channel carrying SQL text) is sufficient.Under sustained attack, one or more CPU cores can be kept at 100% utilization, degrading or completely blocking service for all other users. Because the grouping-stage token limit fires only after the regex work is done, it provides no protection against this attack.Affected use cases include: web applications that accept and display or format SQL; database administration tools; ORM query inspectors; SQL linters and formatters exposed as APIs.### Reproduction artifacts#### `Dockerfile````dockerfileFROM python:3.11-slim# Install build dependenciesRUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*WORKDIR /app# Copy the sqlparse repository source codeCOPY repo/ /app/repo/# Install sqlparse from local source in editable modeRUN pip install --no-cache-dir -e /app/repo/# Copy the PoC script (build context is the parent of vuln-001/)COPY vuln-001/poc.py /app/poc.py# Default: run the PoCCMD [ pytho

漏洞公开时间:2026-08-18 02:17:35
漏洞创建时间:2026-08-18 04:19:36
漏洞详情参考链接:
https://nvd.nist.gov/vuln/detail/CVE-2026-59893

更多参考(点击展开)
参考来源 参考链接 来源链接
https://github.com/andialbrecht/sqlparse
https://github.com/andialbrecht/sqlparse/commit/d1d80602741f77ec78e5a04ce4719244cf32352e
https://security-tracker.debian.org/tracker/CVE-2026-59893
https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-prg7-hcfm-mfcr
https://github.com/advisories/GHSA-prg7-hcfm-mfcr
https://advisory.echohq.com/cve/CVE-2026-59893

漏洞分析指导链接:
https://atomgit.com/openeuler/cve-manager/blob/master/cve-vulner-manager/doc/md/manual.md
漏洞数据来源:
七彩瞬析开源风险感知平台
漏洞补丁信息:

详情(点击展开)
影响的包 修复版本 修复补丁 问题引入补丁 来源
https://github.com/andialbrecht/sqlparse/commit/d1d80602741f77ec78e5a04ce4719244cf32352e osv

二、漏洞分析结构反馈
影响性分析说明:
sqlparse 的词法分析器在每个输入位置逐条尝试 SQL_REGEX 中的全部正则(sqlparse/lexer.py 的 for pos, char in iterable 主循环)。其中三条正则采用「懒惰 dot-all 量词 + 定界符收尾」的形态:1. ((?<! S) $(?:[_A-ZÀ-Ü] w*)? $)[ s S]? 1 —— dollar-quoted 字面量,用反向引用匹配闭合定界符;2. / * +[ s S]? */ —— 多行 Hint 注释;3. / [ s S]? */ —— 多行注释。当输入包含大量不闭合的开定界符时,每个开定界符都要扫描到字符串末尾才能判定失败,整体退化为 O(n^2),即 ReDoS。攻击者只需向任何调用 sqlparse.parse() / format() / split() 的接口投递构造的 SQL 文本即可持续占满 CPU,无需认证、无需用户交互。需要说明的是,grouping 阶段的 MAX_GROUPING_TOKENS 限制在词法分析「完成之后」才生效,无法约束正则的 CPU 开销,因此不构成缓解措施。该漏洞属 CWE-1333(Inefficient Regular Expression Complexity),远程可达、无需权限与用户交互,仅影响可用性。修复方案:回合上游 commit d1d80602741f77ec78e5a04ce4719244cf32352e(上游 0.6.0)。该补丁改用两阶段线性算法——先以 re.finditer 一次性定位全部定界符,再在一次从左到右的遍历中配对开闭定界符(新增 keywords.find_delimited_spans() 与 utils.resolve_paired_delimiters()),并从 SQL_REGEX 中移除上述三条正则。sqlparse 自带测试 428 passed, 3 xfailed 全部通过。
openEuler评分:
7.5
Vector:CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
受影响版本排查(受影响/不受影响):
1.master(0.5.5):受影响
2.openEuler-20.03-LTS-SP4(0.3.1):受影响
3.openEuler-22.03-LTS-SP4(0.4.2):受影响
4.openEuler-24.03-LTS-Next(0.4.4):受影响
5.openEuler-24.03-LTS-SP1(0.4.4):受影响
6.openEuler-24.03-LTS-SP3(0.4.4):受影响
7.openEuler-24.03-LTS-SP4(0.4.4):受影响

修复是否涉及abi变化(是/否):
1.master(0.5.5):否
2.openEuler-20.03-LTS-SP4(0.3.1):否
3.openEuler-22.03-LTS-SP4(0.4.2):否
4.openEuler-24.03-LTS-Next(0.4.4):否
5.openEuler-24.03-LTS-SP1(0.4.4):否
6.openEuler-24.03-LTS-SP3(0.4.4):否
7.openEuler-24.03-LTS-SP4(0.4.4):否

原因说明:
1.master(0.5.5):正常修复
2.openEuler-20.03-LTS-SP4(0.3.1):正常修复
3.openEuler-22.03-LTS-SP4(0.4.2):正常修复
4.openEuler-24.03-LTS-Next(0.4.4):正常修复
5.openEuler-24.03-LTS-SP1(0.4.4):正常修复
6.openEuler-24.03-LTS-SP3(0.4.4):正常修复
7.openEuler-24.03-LTS-SP4(0.4.4):正常修复

likedislike
openeuler-ci-botopeneuler-ci-bot成员
12 天前 添加了label:CVE/UNFIXED
openeuler-ci-bot
openeuler-ci-bot成员
12 天前 评论:

issue处理注意事项:
1. 提交正常修复分支的修复PR时,必须关联当前issue,否则无法关闭当前issue;
2. 模板内容需要填写完整, 无论是受影响或者不受影响都需要填写完整内容;
3. 以下为模板中需要填写完整的内容, 请复制到评论区回复;
注: 内容的关键词(影响性分析说明, openEuler评分, 受影响版本排查(受影响/不受影响), 修复是否涉及abi变化(是/否), 原因说明)不能省略,省略后cve-manager将无法正常解析填写内容.


影响性分析说明:

openEuler评分: (评分和向量)

受影响版本排查(受影响/不受影响):
1.master(0.5.5):
2.openEuler-20.03-LTS-SP4(0.3.1):
3.openEuler-22.03-LTS-SP4(0.4.2):
4.openEuler-24.03-LTS-Next(0.4.4):
5.openEuler-24.03-LTS-SP1(0.4.4):
6.openEuler-24.03-LTS-SP3(0.4.4):
7.openEuler-24.03-LTS-SP4(0.4.4):

修复是否涉及abi变化(是/否):
1.master(0.5.5):
2.openEuler-20.03-LTS-SP4(0.3.1):
3.openEuler-22.03-LTS-SP4(0.4.2):
4.openEuler-24.03-LTS-Next(0.4.4):
5.openEuler-24.03-LTS-SP1(0.4.4):
6.openEuler-24.03-LTS-SP3(0.4.4):
7.openEuler-24.03-LTS-SP4(0.4.4):

原因说明:
1.master(0.5.5):
2.openEuler-20.03-LTS-SP4(0.3.1):
3.openEuler-22.03-LTS-SP4(0.4.2):
4.openEuler-24.03-LTS-Next(0.4.4):
5.openEuler-24.03-LTS-SP1(0.4.4):
6.openEuler-24.03-LTS-SP3(0.4.4):
7.openEuler-24.03-LTS-SP4(0.4.4):


原因说明填写请参考下方表格(注意:版本是否受影响和版本的原因说明必须对应,例如master版本分支受影响,那原因说明只能是受影响对应的原因之一!):

分支状态
原因说明 使用场景
受影响 正常修复 受影响且需要修复(包含升级版本修复)的漏洞;
受影响且已经修复的漏洞(历史修复PR也需要关联issue);
若因特殊原因无法修复,应修改原因说明为【不修复-特殊原因】,并在安委会备案相关情况。
受影响 漏洞仍在分析中 已关注到相关漏洞,正在处理,未明确漏洞影响和修复方案。
受影响 暂不修复-暂无解决方案或补丁 当前没有可用的修复或补救措施。【影响性分析】中应包含有关为什么没有修复或补救措施的详细说明、上游相关PR等。
受影响 不修复-超出修复范围 没有漏洞的修复计划。当版本停维、软件包宣布生命周期终止或弃用使用。
受影响 不修复-特殊原因导致不再修复 如存在其他特殊情况不修复相关漏洞,或评估后无法升级修复,应在openEuler社区安全委员会例会进行说明备案。
【影响性分析】中应包含不发布修复的详细说明、特殊情况还应有安委会会议纪要。
不受影响 不受影响-组件不存在 软件不受影响,因为易受攻击的组件不在产品中。
不受影响 不受影响-已有内置的内联控制或缓解措施 内置的内联控制或缓解措施可防止攻击者利用漏洞
不受影响 不受影响-漏洞代码不能被攻击者触发 易受攻击的组件存在,并且该组件包含易受攻击的代码。但是,易受攻击的代码的使用方式使得攻击者无法进行任何预期的攻击。
不受影响 不受影响-漏洞代码不在执行路径 易受影响的代码在执行过程中不可访问,包括产品的非预期状态。产品不使用也不执行的组件。
不受影响 不受影响-漏洞代码不存在 产品不受影响,因为漏洞背后的代码在产品中不存在。与component_not_present不同的是,有问题的组件存在,但由于某种原因(例如安全的编译器选项)使漏洞的特定代码不存在于组件中。

issue处理具体操作请参考:
https://atomgit.com/openeuler/cve-manager/blob/master/cve-vulner-manager/doc/md/manual.md
pr关联issue具体操作请参考:
https://docs.atomgit.com/docs/help/home/org_project/pullrequests/pr-related-issue

likedislike
openeuler-ci-bot
openeuler-ci-bot成员
12 天前 评论:
参考网址 关联pr 状态 补丁链接
https://www.opencve.io/cve/CVE-2026-59893NoneNonehttps://github.com/andialbrecht/sqlparse/commit/d1d80602741f77ec78e5a04ce4719244cf32352e
https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2026-59893
https://security-tracker.debian.org/tracker/CVE-2026-59893
http://www.cnnvd.org.cn/web/vulnerability/queryLds.tag?qcvCnnvdid=CVE-2026-59893
https://nvd.nist.gov/vuln/detail/CVE-2026-59893NoneNonehttps://github.com/andialbrecht/sqlparse/commit/d1d80602741f77ec78e5a04ce4719244cf32352e
https://ubuntu.com/security/CVE-2026-59893NoneNonehttps://discourse.ubuntu.com/c/project

说明:补丁链接仅供初步排查参考,实际可用性请人工再次确认,补丁下载验证可使用CVE补丁工具
若补丁不准确,烦请在此issue下评论 '/report-patch 参考网址 补丁链接1,补丁链接2' 反馈正确信息,便于我们不断优化工具,不胜感激。
如 /report-patch https://security-tracker.debian.org/tracker/CVE-2021-3997 https://github.com/systemd/systemd/commit/5b1cf7a9be37e20133c0208005274ce4a5b5c6a1

likedislike
openeuler-ci-botopeneuler-ci-bot成员
12 天前 添加了label:sig/sig-python-modules
openeuler-ci-bot
openeuler-ci-bot成员
12 天前 评论:

Welcome To openEuler Community

Hey @openeuler-ci-bot , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: sig-python-modules ,
and any of the maintainers: @shinwell_hu, @yangzhao_kl ,
and any of the committers: @cherry530, @randy1568, @starlet-dx .

likedislike
此处折叠了42条消息 查看更多
openeuler-ci-bot
openeuler-ci-bot成员
9 天前 评论:

@starlet-dx 经过 cve-manager 解析, 已分析的内容如下表所示:

状态 分析项目 内容
已分析 1.影响性分析说明 sqlparse 的词法分析器在每个输入位置逐条尝试 SQL_REGEX 中的全部正则(sqlparse/lexer.py 的 for pos, char in iterable 主循环)。其中三条正则采用「懒惰 dot-all 量词 + 定界符收尾」的形态:1. ((?<!\S)$(?:[_A-ZÀ-Ü]\w*)?$)[\s\S]?\1 —— dollar-quoted 字面量,用反向引用匹配闭合定界符;2. /*+[\s\S]?*/ —— 多行 Hint 注释;3. /*[\s\S]*?*/ —— 多行注释。当输入包含大量不闭合的开定界符时,每个开定界符都要扫描到字符串末尾才能判定失败,整体退化为 O(n^2),即 ReDoS。攻击者只需向任何调用 sqlparse.parse() / format() / split() 的接口投递构造的 SQL 文本即可持续占满 CPU,无需认证、无需用户交互。需要说明的是,grouping 阶段的 MAX_GROUPING_TOKENS 限制在词法分析「完成之后」才生效,无法约束正则的 CPU 开销,因此不构成缓解措施。该漏洞属 CWE-1333(Inefficient Regular Expression Complexity),远程可达、无需权限与用户交互,仅影响可用性。修复方案:回合上游 commit d1d80602741f77ec78e5a04ce4719244cf32352e(上游 0.6.0)。该补丁改用两阶段线性算法——先以 re.finditer 一次性定位全部定界符,再在一次从左到右的遍历中配对开闭定界符(新增 keywords.find_delimited_spans() 与 utils.resolve_paired_delimiters()),并从 SQL_REGEX 中移除上述三条正则。sqlparse 自带测试 428 passed, 3 xfailed 全部通过。
已分析 2.openEulerScore 7.5
已分析 3.openEulerVector AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
已分析 4.受影响版本排查 master:受影响,openEuler-20.03-LTS-SP4:受影响,openEuler-22.03-LTS-SP4:受影响,openEuler-24.03-LTS-Next:受影响,openEuler-24.03-LTS-SP1:受影响,openEuler-24.03-LTS-SP3:受影响,openEuler-24.03-LTS-SP4:受影响
已分析 5.是否涉及abi变化 master:否,openEuler-20.03-LTS-SP4:否,openEuler-22.03-LTS-SP4:否,openEuler-24.03-LTS-Next:否,openEuler-24.03-LTS-SP1:否,openEuler-24.03-LTS-SP3:否,openEuler-24.03-LTS-SP4:否
已分析 6.原因说明 master:正常修复,openEuler-20.03-LTS-SP4:正常修复,openEuler-22.03-LTS-SP4:正常修复,openEuler-24.03-LTS-Next:正常修复,openEuler-24.03-LTS-SP1:正常修复,openEuler-24.03-LTS-SP3:正常修复,openEuler-24.03-LTS-SP4:正常修复

请确认分析内容的准确性, 确认无误后, 您可以进行后续步骤, 否则您可以继续分析.

likedislike
openeuler-ci-botopeneuler-ci-bot成员
9 天前 issue状态由 进行中 改变为 已完成
openeuler-ci-botopeneuler-ci-bot成员
9 天前 关闭了 issue
openeuler-ci-botopeneuler-ci-bot成员
9 天前 删除了label:CVE/UNFIXED
openeuler-ci-botopeneuler-ci-bot成员
9 天前 添加了label:CVE/FIXED