trentm / trentm/python-markdown2
markdown2 malformed HTML tokenizer CPU denial of service
Nobody has claimed this yet.
- 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
- Project: markdown2
- Repo: https://github.com/trentm/python-markdown2
- Pinned ref: 28d94df671eb2a149643310513f84bb00a084072
For more details, see README.md of attached file.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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