Skip to content

Catastrophic Backtracking in Translation Regex #9

Open

Description

@percpyc

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

  1. Create a .jinja file in the theme directory.
  2. 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).
  3. Trigger the translation generation process on the theme (e.g., via the application feature or an automated pipeline).
  4. The application executes text.matchAll(TRANS_RE) on the malicious file, resulting in exponential backtracking.
  5. 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.

Private vulnerability report

https://github.com/zidsa/vitrin-cli/security/advisories/GHSA-q5hr-g623-qfqc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions