Repository navigation
security(detector): ReDoS guard on third-party regex overrides (#829) - #842
Merged
Merged
Conversation
Enforcement at the trust boundary — _load_regex_overrides (plugin/override
path) only; curated built-in DEFAULT_PATTERNS are exempt per threat model
(ReDoS is an external-input vector; built-ins are the defense line, not the
threat).
- config/plugin_validator.py: _has_nested_quantifier — char-by-char scanner
(star height > 1, same criterion as safe-regex/eslint). Escape-aware
(\+, \(, \)), character-class-aware ([+*]), bounded-brace-aware
({2,5} vs {2,}). Replaces regex-over-regex which false-positived on
PHONE_BR's escaped literals. _validate_item also reports ReDoS issues.
- core/detector.py: _load_regex_overrides skips (with PluginValidationWarning)
override patterns with nested quantifiers or re.error; skip is per-item,
scan continues. __init__ compile loop stays simple — built-ins trusted.
- tests/test_redos_guard.py: 8 tests — dangerous/safe heuristic shapes,
validator issue, detector skip (ReDoS + invalid regex, good pattern in same
file still loads), and CALIBRATION: every DEFAULT_PATTERN must pass the
heuristic so it never drifts into rejecting curated patterns again.
Closes #829
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ReDoS guard (#829)
Threat model (per operator decision on #829): ReDoS is an external-input vector. Enforcement happens at the trust boundary —
_load_regex_overrides(third-party plugin/override path) — while curated built-inDEFAULT_PATTERNSare exempt. Calibration tests keep the heuristic honest: every built-in must pass the guard, so it never drifts into rejecting curated patterns again (the PHONE_BR false-positive class).Design
config/plugin_validator.py—_has_nested_quantifier: char-by-char scanner, "star height > 1" criterion (same assafe-regex/eslint). Replaces a regex-over-regex approach that false-positived on PHONE_BR's escaped literals (\+55,\(,\)). Handles:[+*]) → literals?and{2,5}never trigger; unbounded*,+,{2,}do((a+)b)+flagged, conservative by design)core/detector.py—_load_regex_overrides: per-item skip withPluginValidationWarningfor nested-quantifier patterns andre.errorinvalid regex. Skip is per-item — a good pattern in the same plugin file still loads; the scan never crashes.__init__compile loop unchanged — built-ins trusted, overrides pre-filtered.Tests (8, all passing)
(a+)+,(\w*)*,([a-z]+)*,(x{2,})+,((a+)b)+\+/\(),(a?)+,([+*]\d)+,(a{2,5})+DEFAULT_PATTERNSpass the heuristic and compileLocal gate
./scripts/check-all.sh: 1294 passed, 5 skipped ✅Closes #829
Made with Cursor