Skip to content

fix(validators): stop the version-label regex stalling the PII scan on long identifiers - #684

Merged
chrisknvidia merged 3 commits into
mainfrom
fix/christopherk/shell-word-regex-backtracking
Nov 16, 2026
Merged

chrisknvidia merged 3 commits into
mainfrom
fix/christopherk/shell-word-regex-backtracking

Conversation

@chrisknvidia

Copy link
Copy Markdown
Collaborator

Summary

The Tier 1 PII scan can hang on one line of a skill. A long run of letters before an IPv4-shaped value is enough:

aaaaaaaaaaaaaaaaaaaaaaaa = "8.8.0.8"

On main, SecurityValidator().validate_pii_only() takes 0.05 s for a 20-letter name, 0.16 s for 22 and 0.59 s for 24. It roughly doubles with every letter, so 30 letters is about a minute and 80 letters never finishes.

Cause

When the scan finds an IPv4-shaped value, _is_version_literal looks at the 80 characters before it for a version label, using _VERSION_LABEL_PATTERN. Two of its three branches described the camel-case words around the label as a repeated word group:

  • (?:[A-Za-z][a-z0-9]*)* before Version or Tag
  • (?:[A-Z][A-Za-z0-9]*)* and (?:[A-Z][A-Za-z0-9]*)+ after it

A run of letters can be split into such words in exponentially many ways. When no label follows, the regex engine tries all of them before giving up.

These are the three py/redos code-scanning alerts open on main (alerts 5, 6 and 7). Only the first group can be made to blow up today, because the other two are always followed by a match. All three are rewritten so the alerts close and the pattern stays safe if it is extended.

Fix

Each repeated group is written as a single run, which matches the same strings with only one way to do it:

Before After
(?:[A-Za-z][a-z0-9]*)* (?:[A-Za-z][A-Za-z0-9]*)?
(?:[A-Z][A-Za-z0-9]*)* (?:[A-Z][A-Za-z0-9]*)?
(?:[A-Z][A-Za-z0-9]*)+ [A-Z][A-Za-z0-9]*

No behaviour change is intended: the pattern has no capture groups and its only caller uses the match positions.

Please look at

  • The equivalence claim. I compared the old and new patterns' match positions on every string of up to 7 characters over T a g s A 1 _ space (2.4 million strings) and on 400,000 random strings built from label words and identifier pieces. There were no differences. That is strong evidence, not a proof.

Verification

  • I am familiar with the Contributing Guidelines

  • Added or updated focused tests

  • Updated documentation for user-visible changes (none needed)

  • Ran make lint (ruff check on the changed files)

  • Ran make test

  • Ran make build

  • Did not add credentials, private datasets, or proprietary benchmark content

  • New test test_long_identifiers_before_ip_values_do_not_stall_the_scan scans a skill with four 76-character plain identifiers and four long version labels, in a subprocess with a 60 second limit. It checks that the plain identifiers' values are still reported and the labelled ones are not.

  • With the old pattern restored, the new test fails on the 60 second limit. With the fix it passes in about a second.

  • tests/validators/test_security.py passes in full: 1485 passed, 1 skipped (macOS, Python 3.12).

  • With the fix, the pattern scans 100,000 letters in under 10 ms.

Not verified: the full suite was not run locally, and the code-scanning alerts will only show as closed after CodeQL runs on main.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

One entry under Fixed.

…n long identifiers

When the PII scan finds an IPv4-shaped value it looks for a version label
in the 80 characters before it. The label pattern described the camel-case
words around the label as a repeated word group, and a run of letters can
be split into such words in exponentially many ways. A 24-letter name
before the value took 0.6 seconds to scan, and every further letter
roughly doubled that.

Each repeated group is now a single run that matches the same strings.
The old and new patterns give the same matches on 2.8 million test
strings. A new test scans long identifiers in a subprocess with a time
limit and checks the findings are unchanged.

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
Signed-off-by: Christopher Kevin <christopherk@nvidia.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of c7c23954: no actionable issues found in the changed code. Focused validation and its scope are recorded inline. This addresses the same backtracking issue as #689.

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 48b7c5b3 (the main merge leaves this PR's diff unchanged from c7c23954). No issues found in this PR.

Checked: I compared match spans of the old pattern and this one with finditer on 100k random strings built from label words, letters, digits and separators. There were no differences. All three rewritten groups scan 80-char adversarial runs in under 0.1 ms. This closes all three open py/redos alerts (5, 6, 7). Focused tests pass locally (17 passed). The subprocess-with-timeout test turns a regression into a failure, not a hang.

Note: #689 (stanfish06) fixes the same regex independently. It changes only the prefix group and leaves alerts 6 and 7 open, so the two PRs conflict. Only one should merge. If this one is chosen, consider adding #689's real-world picard_RevertOriginalBaseQualitiesAndAddMateCigar/2.18.2.1 case and its PackageVersion/dockerImageTag label variants. Then close #689 with credit, and keep a single CHANGELOG entry.

@chrisknvidia
chrisknvidia marked this pull request as ready for review November 16, 2026 21:05
@chrisknvidia
chrisknvidia merged commit b72805b into main Nov 16, 2026
29 checks passed
@chrisknvidia
chrisknvidia deleted the fix/christopherk/shell-word-regex-backtracking branch November 16, 2026 21:07

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +8616 to +8620
def test_long_identifiers_before_ip_values_do_not_stall_the_scan(self, tmp_path: Path) -> None:
"""Regression (CWE-1333): the version-label pattern could split a run of letters in exponentially many
ways, so a 30-letter identifier before an IPv4-shaped value stalled the PII scan for about a minute and
every further letter doubled that. Runs in a subprocess so that a slow scan fails the timeout instead of
hanging the suite; the limit is generous because the scan takes about a second."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Incomplete local contribution gates

The PR records that make test and make build were not run. The contribution gate requires both locally; focused validator tests leave that requirement incomplete.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

stanfish06 added a commit to stanfish06/skillquarium that referenced this pull request Nov 16, 2026
NVIDIA/SkillEvaluator#684 fixed the version-label regex that made the
PII scan backtrack exponentially on galaxy-bridge's Galaxy tool ids. No
release has it yet, so Tier 1 now runs NVIDIA main at c6e2d020 through
uvx --from git+...; results record it as 0.9.0+c6e2d020 because the
commit still reports 0.9.0. Existing 0.9.0 results stay until their
skill trees change.

Reverts 0ef1a4e: restores the skill, its domain, toggle snapshot entry,
wrapper note and embedding vector, and regenerates the goldens. Records
galaxy-bridge's Tier 1 result (failed, 90 A; full scan took ~6 min).

Move back to a PyPI pin once a release after 0.9.0 ships.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants