Control: tags -1 + fixed-upstream patch
Hi,
CVE-2026-88753 (ReDoS in metadata parsing, gist by NanaSec) is upstream
issue #741:
https://www.google.com/url?q=https://github.com/trentm/python-markdown2/issues/741&source=gmail&ust=1793790559760000&sa=E
It is fixed on master by PR #742, merged 2026-10-19:
https://www.google.com/url?q=https://github.com/trentm/python-markdown2/pull/742&source=gmail&ust=1793790559760000&sa=E
commit b624eafc72 "Avoid overlapping regex matches in _key_val_list_pat"
merge a3716b5e0aeba16b6e85965b2e5019d174328f36
No upstream release contains it yet (the latest tag is 2.5.5).
I checked it against Debian's 2.5.4-4. The installed
/usr/lib/python3/dist-packages/markdown2.py is identical to upstream
2.5.4 lib/markdown2.py.
1) Applying the patch: the lib/markdown2.py hunks apply to 2.5.4 with
offsets only (-27/-36), no fuzz. The test/test_redos.py hunk does not
fit 2.5.4's older ReDoS harness, which has no extras parameter.
The attached patch is the lib-only change, rebased onto 2.5.4.
2) Reproducer from the upstream issue: markdown() with
extras=["metadata"] on "---\nkey: -<N spaces>\n---\n\n# hello\n":
N 2.5.4-4 patched
4000 0.090 s 0.0025 s
8000 0.358 s 0.0003 s
16000 1.397 s 0.0003 s
32000 5.603 s 0.0004 s
The unpatched time grows quadratically; the patched time stays flat.
3) Regression check: I rendered all 238 upstream test inputs (*.text
under test/) with extras=["metadata"] through the unpatched and
patched modules and compared the HTML and the metadata.
- 233 are identical.
- 3 differ only because of the randomized e-mail address
obfuscation; unpatched vs unpatched differs on the same 3.
- 2 differ in metadata, and both are documents that are not metadata
documents (admonitions_with_fenced_code_blocks,
fenced_code_blocks_issue135) that I force-rendered with the
metadata extra.
The four dedicated metadata cases (metadata, metadata2, metadata3,
emacs_file_vars_with_metadata) produce the expected .metadata and
.html output both before and after.
List values such as "- a: b" and plain "- one/- two" lists parse the
same before and after.
I could not run upstream's own test.py in this environment, so the
above is a differential comparison, not the full testsuite run.
Regards
--- a/lib/markdown2.py 2026-11-03 06:07:02.502874898 -0500
+++ b/lib/markdown2.py 2026-11-03 06:07:02.564633814 -0500
@@ -603,17 +603,16 @@
(?:
{1}:(?:\n+[ \t]+.*)+ # indented lists
)|(?:
- (?:{1}:\s+>(?:\n\s+.*)+?) # multiline long descriptions
- (?=\n{1}:\s*.*\n|\s*\Z) # match up until the start of the next key:value definition or the end of the input text
+ {1}:\s+>(?:\n+[ \t]+.*)+ # multiline long descriptions
)|(?:
- {1}:(?! >).*\n? # simple key:value pair, leading spaces allowed
+ {1}:[^\n]*\n? # simple key:value pair, leading spaces allowed
)
){0} # optional closing fence
- '''.format(r'(?:---[\ \t]*\n)?', r'[\S \t]*\w[\S \t]*\s*'), re.MULTILINE | re.VERBOSE
+ '''.format(r'(?:---[\ \t]*\n)?', r'[ \t]*[^\s:\r\n][^:\r\n]*'), re.MULTILINE | re.VERBOSE
)
_key_val_list_pat = re.compile(
- r"^-(?:[ \t]*([^\n]*)(?:[ \t]*[:-][ \t]*(\S+))?)(?:\n((?:[ \t]+[^\n]+\n?)+))?",
+ r"^-[ \t]*([^\n]*)(?:\n((?:[ \t]+[^\n]+\n?)+))?",
re.MULTILINE,
)
_key_val_dict_pat = re.compile(
@@ -645,21 +644,28 @@
# List
if vs.startswith("-"):
r: list[Any] = []
- # the regex used has multiple capturing groups, so
- # returned type from findall will be List[List[str]]
- match: list[str]
+ # returned type from findall will be list[tuple[str, ...]]
for match in re.findall(self._key_val_list_pat, vs):
- if match[0] and not match[1] and not match[2]:
- r.append(match[0].strip())
- elif match[0] == ">" and not match[1] and match[2]:
- r.append(match[2].strip())
- elif match[0] and match[1]:
- r.append({match[0].strip(): match[1].strip()})
- elif not match[0] and not match[1] and match[2]:
- r.append(parse_structured_value(match[2]))
+ if len(match) == 2:
+ val, block = match[0], match[1]
+ if val and not block:
+ r.append(val.strip())
+ elif val == ">" and block:
+ r.append(block.strip())
+ elif not val and block:
+ r.append(parse_structured_value(block))
else:
- # Broken case
- pass
+ if match[0] and not match[1] and not match[2]:
+ r.append(match[0].strip())
+ elif match[0] == ">" and not match[1] and match[2]:
+ r.append(match[2].strip())
+ elif match[0] and match[1]:
+ r.append({match[0].strip(): match[1].strip()})
+ elif not match[0] and not match[1] and match[2]:
+ r.append(parse_structured_value(match[2]))
+ else:
+ # Broken case
+ pass
return r