Skip to content

Cubic backtracking in the destructive-command patterns of the guardrail classifier

Moderate
Neboy72 published GHSA-m446-mvgq-w52p Oct 28, 2026

Software

nexus-memory

Affected versions

>= 0.0.0, < 0.22.34

Patched versions

0.22.34

Description

Several patterns in src/nexus_memory/guardrails.py have the shape A.*B, and their cost grows with the cube of the command length when the command repeats the first part. The worst is \bgit\b.*clean.*-[fd] (line 97). Measured on this repository, in the run recorded below, with a command made of repeated "git clean ": 0.44 s for 8,000 characters and 3.45 s for 16,000.

The same shape appears in the pip, npm and brew install patterns, in dd ... of, in find ... -delete, and in the DELETE ... collection and drop ... collection patterns.

classify_action() runs before a terminal command is executed in every consumer: the Hermes memory plugin, the MCP server and the quick-check path. Nothing caps the length of a command that is classified, so a command shaped by a web page or by a tool result can hold the guardrail for minutes. The Claude Code hook script ships its own pattern list and does not call this module.

Fixed in 0.22.34. The eight patterns are written as (?m)^(?>.*?A).*?B, which scans each line once instead of retrying from every occurrence of A. On the same machine the 16,000 character command now takes 0.1 ms instead of 3.45 s, and a seeded generator over 480,000 commands finds no verdict difference against the old patterns. The rewrite is in commit f2f21f4 of this repository, and tests/test_guardrails_linear.py covers each of the eight patterns, including the case that used to be the worst: a repeated prefix that never reaches the terminator.

Simin Yuan (@simin-yuan) reported this issue and wrote the fix with its regression tests. He is credited as finder below; his name is on the commit and in the changelog.

Severity

Moderate

CVE ID

No known CVE

Weaknesses

Inefficient Regular Expression Complexity

The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. Learn more on MITRE.

Credits