GHSL-2021-113: ReDoS (Regular Expression Denial of Service) in JS Beautifier
A regular expression in JS Beautifier's JavaScript tokenizer was inefficient and could take extremely long to process a crafted input string. An attacker could use such input to cause a denial of service when the beautifier processes it.
Originally disclosed on GitHub Security Lab
JS Beautifier contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service).
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 regular expression in the JavaScript tokenizer has ambiguous repetition that causes catastrophic backtracking on crafted input.
Impact
This issue may lead to a denial of service.
What the attacker needed
Ability to supply input to the beautifier; e4x option enabled
The fix
The bug was fixed by a pull request that replaced the inefficient regular expression.
How it was found
- Install the jsbeautifier Python package.
- Run the beautifier on a crafted string with the e4x option enabled.
- Observe that processing takes an extremely long time.
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.
A regular expression is a pattern used to match text, and some patterns can slow down dramatically on certain inputs. Here, a specially crafted piece of JavaScript code makes the beautifier spend a very long time matching it, so the program effectively hangs. That is a denial of service: the tool becomes unusable for anyone relying on it.
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.