shared/redaction: register_pattern() allows arbitrary regex without ReDoS validation — potential DoS vulnerability #10563

Open
opened 2026-04-18 17:16:28 +00:00 by HAL9000 · 0 comments
Owner

Metadata

Commit: Current HEAD (to be updated upon branch creation)
Branch: fix/redaction-redos-validation

Background and Context

The register_pattern() function in src/cleveragents/shared/redaction.py (lines 218-230) accepts arbitrary regex patterns without validating them for Regular Expression Denial of Service (ReDoS) vulnerabilities. This creates a security vulnerability where a malicious or poorly-written pattern could cause catastrophic backtracking, leading to CPU exhaustion and application hang.

The function is used in error_handling.py to register patterns at module load time, making it a potential attack surface if pattern registration is exposed to user input or external configuration.

Expected Behavior

The register_pattern() function should:

  1. Validate incoming regex patterns for ReDoS vulnerabilities before compilation
  2. Reject patterns that contain known ReDoS patterns (nested quantifiers, alternation with overlapping patterns, etc.)
  3. Provide clear error messages when a pattern is rejected
  4. Maintain backward compatibility with existing safe patterns

Acceptance Criteria

  • register_pattern() validates regex complexity before compiling
  • Patterns with nested quantifiers (e.g., (a+)+b) are rejected with ValueError
  • Patterns with alternation overlaps are detected and rejected
  • Error messages clearly indicate the ReDoS vulnerability
  • All existing safe patterns in the codebase continue to work
  • Unit tests cover ReDoS detection for common vulnerable patterns
  • Unit tests verify that safe patterns are accepted
  • Documentation updated to explain pattern validation requirements

Subtasks

  • Implement _has_redos_vulnerability() helper function with regex complexity checks
  • Add validation logic to register_pattern() function
  • Create unit tests for ReDoS pattern detection
  • Create unit tests for safe pattern acceptance
  • Update docstring for register_pattern() with validation details
  • Run full test suite to ensure no regressions
  • Update CHANGELOG.md with security fix entry

Definition of Done

This issue is complete when:

  1. All acceptance criteria are met
  2. All subtasks are checked off
  3. Unit test coverage for the redaction module remains ≥ 97%
  4. All existing tests pass
  5. Code review approved by at least one maintainer
  6. Changes merged to main branch

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit**: Current HEAD (to be updated upon branch creation) **Branch**: `fix/redaction-redos-validation` ## Background and Context The `register_pattern()` function in `src/cleveragents/shared/redaction.py` (lines 218-230) accepts arbitrary regex patterns without validating them for Regular Expression Denial of Service (ReDoS) vulnerabilities. This creates a security vulnerability where a malicious or poorly-written pattern could cause catastrophic backtracking, leading to CPU exhaustion and application hang. The function is used in `error_handling.py` to register patterns at module load time, making it a potential attack surface if pattern registration is exposed to user input or external configuration. ## Expected Behavior The `register_pattern()` function should: 1. Validate incoming regex patterns for ReDoS vulnerabilities before compilation 2. Reject patterns that contain known ReDoS patterns (nested quantifiers, alternation with overlapping patterns, etc.) 3. Provide clear error messages when a pattern is rejected 4. Maintain backward compatibility with existing safe patterns ## Acceptance Criteria - [ ] `register_pattern()` validates regex complexity before compiling - [ ] Patterns with nested quantifiers (e.g., `(a+)+b`) are rejected with `ValueError` - [ ] Patterns with alternation overlaps are detected and rejected - [ ] Error messages clearly indicate the ReDoS vulnerability - [ ] All existing safe patterns in the codebase continue to work - [ ] Unit tests cover ReDoS detection for common vulnerable patterns - [ ] Unit tests verify that safe patterns are accepted - [ ] Documentation updated to explain pattern validation requirements ## Subtasks - [ ] Implement `_has_redos_vulnerability()` helper function with regex complexity checks - [ ] Add validation logic to `register_pattern()` function - [ ] Create unit tests for ReDoS pattern detection - [ ] Create unit tests for safe pattern acceptance - [ ] Update docstring for `register_pattern()` with validation details - [ ] Run full test suite to ensure no regressions - [ ] Update CHANGELOG.md with security fix entry ## Definition of Done This issue is complete when: 1. All acceptance criteria are met 2. All subtasks are checked off 3. Unit test coverage for the redaction module remains ≥ 97% 4. All existing tests pass 5. Code review approved by at least one maintainer 6. Changes merged to main branch --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10563
No description provided.