---
title: "Is that regex really a ReDoS risk? Measure it in the engine you run | Proofline"
description: "A ReDoS comment rests on two facts: who controls the input or the pattern, and whether your regex engine backtracks."
url: https://proofline.sh/learn/ai-review-regex-redos-comment/
---

[Learning center](/learn/)

# Is that regex really a ReDoS risk? Measure it in the engine you run

A ReDoS comment rests on two facts: who controls the input or the pattern, and whether your regex engine backtracks. Time the pattern on growing inputs in the engine the code imports; change or bound it if attacker-reachable input takes superlinear time, and dismiss with the numbers if it does not.

Code review The Proofline team November 22, 2026 4 min read

## Check the input and the engine

OWASP describes the attack as exploiting the fact "that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size)." It names two routes: a vulnerable pattern applied to attacker-supplied text, and a pattern that is itself built from user input. [OWASP ReDoS](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS) A comment that names neither route describes, at most, a slow regex.

The engine matters as much as the pattern. Go's `regexp` package documents that its matching runs in time linear in the size of the input. [Go regexp](https://pkg.go.dev/regexp) Python's `re`, Java's `java.util.regex` and JavaScript's `RegExp` backtrack, so nested or overlapping quantifiers can cost exponential time on input that almost matches. Two backtracking engines can still differ on the same pattern, which is why the measurement has to use the library the code imports.

## A tool-call regex that slowed in one engine

In April 2026, a vLLM pull request added a tool-call parser for LFM2 models. Gemini Code Assist's summary said: "A high-severity security issue was identified regarding the TOOL\_CALL\_REGEX, which is vulnerable to Regular Expression Denial of Service (ReDoS) due to complex nested quantifiers." It added: "It is recommended to simplify this regex, as the code already performs robust validation using ast.parse." [Review](https://github.com/vllm-project/vllm/pull/39243#pullrequestreview-4071815745)

The pattern, before the change, nested repeated groups that each contain `.*`:

```
TOOL_CALL_REGEX = re.compile(
    r"\[([a-zA-Z]+\w*\(([a-zA-Z]+\w*=.*,\s*)*([a-zA-Z]+\w*=.*\s)?\)"
    r",\s*)*([a-zA-Z]+\w*\(([a-zA-Z]+\w*=.*,\s*)*"
    r"([a-zA-Z]+\w*=.*\s*)?\)\s*)+\]",
    re.DOTALL,
)
```

[Code before the change](https://raw.githubusercontent.com/vllm-project/vllm/a88c01941fc35f3e07667856d404818d5c779a5d/vllm/tool_parsers/lfm2_tool_parser.py)

The input is model output, which a user's prompt can steer, so treat it as attacker-influenced. For this guide, the pattern was timed on a call that opens and never closes: `[f(` followed by `a=1,` repeated n times. With Python's standard `re`, two runs took roughly 24 to 30 ms at n = 16, 95 to 123 ms at n = 18 and 421 to 614 ms at n = 20, three to six times longer for every two more repetitions. But the parser imports the third-party [`regex`](https://pypi.org/project/regex/) module (`import regex as re`), not the standard library. In `regex` 2026.11.19, the same inputs finished in under 0.1 ms, and a one-minute random search over call-like fragments found nothing slower than 7.3 ms. That search does not prove no slow input exists. The call also already passed `timeout=envs.VLLM_TOOL_PARSE_REGEX_TIMEOUT_SECONDS`, which defaults to one second.

So the comment was right about the pattern's shape and overstated the risk in the shipped engine. The author changed it anyway, in commit `a51d3d2`, "fix: change tool call regex to be a simple structural check", to `re.compile(r"\[.*\]$", re.DOTALL)`, and left the real validation to `ast.parse`. [Commits](https://github.com/vllm-project/vllm/pull/39243/commits) The pull request merged on 8 May 2026. When a simpler pattern does the same job, replacing it costs less than proving the old one safe in every engine it might meet.

## A pattern built from constants

An ArcadeDB pull request from October 2026 records the opposite outcome. It extended a redactor for support diagnostics so passwords inside the `defaultDatabases` setting are masked. The author's description lists each review round: "CodeRabbit raised one valid Major finding", fixed with a test, and "Its ast-grep ReDoS note was not applicable: the pattern is built from constants only and uses possessive quantifiers." [Pull request](https://github.com/ArcadeData/arcadedb/pull/9678) The note itself is not visible on the page; the description is the record of it.

Both halves of that reason are checkable. Every piece the pattern is built from is a `private static final String` in the class, so no input reaches the pattern. The input text is log and configuration content, which can be long, and the pattern's quantifiers are possessive (`*+`, `++`), which keep what they match and never give characters back to let the rest of the pattern retry. [Java `Pattern`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/regex/Pattern.html) On OpenJDK 21, the merged `DEFAULT_DATABASES` pattern matched a line of 100,000 repeated `a[u:p] ;` entries, about 900,000 characters, in 16 to 17 ms. A copy with the possessive quantifiers changed to greedy ones threw `StackOverflowError` at 1,000 entries, the failure a code comment in the same class warns about for long quoted values. The dismissal holds. The pull request merged on 10 October 2026.

## Decide from the input and the measurement

| Input and engine | Evidence to check | Response |
| --- | --- | --- |
| Pattern built from user input | Where the pattern string comes from | Change: escape the input, or use a linear-time engine |
| Attacker-reachable text, backtracking engine, nested or overlapping quantifiers | Time on growing near-miss inputs in the imported library | Change the pattern, or bound input length and match time |
| Same, but the timing stays flat | The measurement, with the library version | Dismiss with the numbers, or simplify if it is cheap |
| Constant pattern with possessive or atomic groups | The constants and a long-input timing | Dismiss, citing both |
| Linear-time engine, such as Go's `regexp` | The import | Dismiss, naming the engine |
| Input only from trusted configuration | Who writes that configuration | Dismiss with the trust boundary |

Keep the timing script with the reply, since the next person to change the pattern will need it. If the reviewer repeats the note on every push, the [guide to findings your linter already covers](/learn/review-findings-already-covered-by-lint/) explains how to sort rule-based notes from a reviewer's own findings.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [An XSS comment on raw HTML: trace the data before you sanitize](/learn/ai-review-xss-comment/)
    
    Code review The Proofline team November 22, 2026 4 min read
    
-   ### [Which review findings does your linter already cover?](/learn/review-findings-already-covered-by-lint/)
    
    Code review The Proofline team November 20, 2026 3 min read
