trentm / trentm/python-markdown2

markdown2 malformed HTML tokenizer CPU denial of service

Open
#707 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Python
Stars
2.8k
Forks
459
Avg merge
2d 19h
Merged PRs (30d)
4

Description

Describe the bug
python-markdown2 can spend unbounded CPU in its inline HTML tokenizer when rendering attacker-controlled Markdown containing repeated malformed tag fragments. At the pinned commit, the public markdown2.markdown() path can pass that text to _sorta_html_tokenize_re.split() in lib/markdown2.py, and a roughly 60 KB input deterministically reaches the local one-second timeout oracle. Applications that render untrusted Markdown synchronously can therefore have request workers tied up by a single document.

To Reproduce
INT-regex-markdown2-html-tokenizer-redos.zip

See attached file.

bash ./poc/run.sh
timed_out after 1s

Expected behavior
Tag-branch regex fails to match the malformed fragment in linear time.

Debug info

For more details, see README.md of attached file.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/markdown2.py at _sorta_html_tokenize_re.split() and reproduce the issue with bash ./poc/run.sh using the attached proof of concept. Inspect the tag-branch regex and verify that malformed fragments no longer trigger the one-second timeout while preserving expected HTML tokenization behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.