Repository navigation
Description
Catastrophic Backtracking in Translation Regex
Affected commit
Repository: https://github.com/zidsa/vitrin-cli
Git commit: 45e59e4983cec15e11845582d337ff122f62c61c
Description
The regular expression TRANS_RE used to extract translation keys contains a nested grouping (?:\\.|(?!\1).)* that is vulnerable to catastrophic backtracking. The alternatives \\. (which matches a backslash followed by any character) and (?!\1). (which matches any character except the quotation mark) are overlapping. Specifically, a sequence starting with a backslash and followed by a non-quote character can be matched in two different ways by the regex engine at each iteration. When matchAll is executed on untrusted .jinja template content containing a long sequence of such characters without a matching closing quote (e.g., _("\a\a\a...), the regex engine explores exponentially many matching paths before failing. This causes the event loop or process to hang, leading to a Denial of Service.
Steps to Reproduce
- Create a .jinja file in the theme directory.
- Insert a payload such as _("\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a (without the closing quote).
- Trigger the translation generation process on the theme (e.g., via the application feature or an automated pipeline).
- The application executes text.matchAll(TRANS_RE) on the malicious file, resulting in exponential backtracking.
- Observe the Node.js process consuming 100% CPU and hanging indefinitely.
Expected impact
- Complete Denial of Service (DoS) of the translation generation process.
- Potential pipeline or server exhaustion if triggered continuously in an automated or user-facing environment.
Demonstrated Impact
A crafted translation expression triggered catastrophic backtracking and kept the parser busy for more than 19 seconds with 26 repetitions.
Scope and Limitations
The attacker must cause the CLI to process a crafted theme translation file. Timing varies by runtime and hardware, while the superlinear behavior remains the relevant signal.
Activity
fix: stop the translation regex from backtracking exponentially (zidsa#9
fix: stop the translation regex from backtracking exponentially (zidsa#9