GHSL-2022-098: Quadratic complexity algorithm in cmark - CVE-2023-22484
A crafted markdown document with many repetitions of the characters '<!--' triggers quadratic complexity in cmark's HTML comment scanner, causing excessive CPU usage. 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 HTML comment scanner is called repeatedly for each '<' character and scans to the end of the line, leading to quadratic time complexity.
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; attacker can submit crafted markdown
The fix
The bug was fixed by the maintainer.
How it was found
- Generate a markdown document containing many repetitions of '<!--'.
- Pipe the document into cmark.
- Observe that 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.
This is a denial-of-service bug. When cmark processes a specially crafted markdown file, it takes much longer than it should, growing quadratically with the input size. An attacker could send such a file to a website that uses cmark, making the server slow or unresponsive.
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.