Repository navigation
fix(validators): stop the version-label regex stalling the PII scan on long identifiers - #684
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
| 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.""" |
There was a problem hiding this comment.
🔍 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
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>
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:
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_literallooks 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]*)*beforeVersionorTag(?:[A-Z][A-Za-z0-9]*)*and(?:[A-Z][A-Za-z0-9]*)+after itA 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/redoscode-scanning alerts open onmain(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:
(?:[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
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 checkon the changed files)Ran
make testRan
make buildDid not add credentials, private datasets, or proprietary benchmark content
New test
test_long_identifiers_before_ip_values_do_not_stall_the_scanscans 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.pypasses 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
CHANGELOG.mdOne entry under Fixed.