GHSL-2022-128: Quadratic complexity algorithm in cmark - CVE-2023-22486
A crafted markdown document with many repetitions of a specific character sequence triggers quadratic complexity in cmark's bracket handling, causing excessive CPU use. An attacker could use this to cause a denial-of-service on websites that render markdown with cmark.
Originally disclosed on GitHub Security Lab
A crafted markdown document can trigger a quadratic complexity algorithm in cmark.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the loop in handle_close_bracket iterates over all previous openers for each closing bracket, leading to quadratic time complexity when many such brackets are present.
Impact
This issue could be used in a denial-of-service attack on websites that use cmark to render markdown documents.
What the attacker needed
Cmark used to render untrusted markdown
The fix
The issue was fixed in cmark and cmark-gfm.
How it was found
- Generate a markdown document with many repetitions of the sequence '![[]()'.
- Pipe the document into cmark for processing.
- Observe that the running time increases quadratically as the number of repetitions grows.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Markdown is a simple formatting language; cmark is a program that converts it to HTML. The bug means that a specially crafted markdown file can make cmark take a very long time to process, which could slow down or crash a website that uses cmark.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.