shared/redaction: _redact_dict_inner() has unbounded recursion depth — stack overflow on deeply nested dicts #10555

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

Metadata

Commit Message: Fix unbounded recursion in _redact_dict_inner() to prevent stack overflow on deeply nested dictionaries

Branch Name: fix/redaction-recursion-depth

Background and Context

The _redact_dict_inner() function in src/cleveragents/shared/redaction.py (lines 170-189) recursively processes nested dictionaries and lists without any depth limit. This design flaw allows a malicious or malformed input with deeply nested structures to cause a RecursionError and crash the application.

This is a security concern as it can be exploited for denial-of-service attacks, and a stability concern for legitimate use cases involving deeply nested data structures.

Expected Behavior

The redaction system should safely handle deeply nested dictionaries and lists by:

  1. Enforcing a configurable maximum recursion depth (default: 100 levels)
  2. Raising a clear, descriptive error when the depth limit is exceeded
  3. Allowing the depth limit to be customized per call if needed
  4. Maintaining backward compatibility with existing code

Acceptance Criteria

  • _redact_dict_inner() accepts a max_depth parameter (default: 100)
  • Function tracks current recursion depth and validates before recursing
  • RecursionError is prevented; ValueError is raised instead with clear message
  • Error message includes the exceeded depth limit for debugging
  • All existing tests pass without modification
  • New unit tests cover:
    • Normal operation with shallow dicts (depth < 10)
    • Normal operation with moderately nested dicts (depth 50-100)
    • Proper error handling when max_depth is exceeded
    • Custom max_depth parameter works correctly
    • Lists containing deeply nested dicts are also protected
  • Code coverage remains >= 97%

Subtasks

  • Add max_depth parameter to _redact_dict_inner() function signature
  • Implement depth tracking and validation logic
  • Update redact_dict() public API to accept optional max_depth parameter
  • Add comprehensive unit tests for depth limit enforcement
  • Update docstrings with depth limit documentation
  • Verify no performance regression on typical use cases
  • Update CHANGELOG.md with security fix note

Definition of Done

This issue is complete when:

  1. The _redact_dict_inner() function safely rejects deeply nested structures
  2. All unit tests pass (including new depth limit tests)
  3. Code coverage remains >= 97%
  4. No RecursionError can be triggered by any input
  5. Documentation clearly explains the depth limit and how to customize it
  6. The fix is backward compatible with existing code

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit Message:** Fix unbounded recursion in _redact_dict_inner() to prevent stack overflow on deeply nested dictionaries **Branch Name:** fix/redaction-recursion-depth ## Background and Context The `_redact_dict_inner()` function in `src/cleveragents/shared/redaction.py` (lines 170-189) recursively processes nested dictionaries and lists without any depth limit. This design flaw allows a malicious or malformed input with deeply nested structures to cause a `RecursionError` and crash the application. This is a security concern as it can be exploited for denial-of-service attacks, and a stability concern for legitimate use cases involving deeply nested data structures. ## Expected Behavior The redaction system should safely handle deeply nested dictionaries and lists by: 1. Enforcing a configurable maximum recursion depth (default: 100 levels) 2. Raising a clear, descriptive error when the depth limit is exceeded 3. Allowing the depth limit to be customized per call if needed 4. Maintaining backward compatibility with existing code ## Acceptance Criteria - [ ] `_redact_dict_inner()` accepts a `max_depth` parameter (default: 100) - [ ] Function tracks current recursion depth and validates before recursing - [ ] `RecursionError` is prevented; `ValueError` is raised instead with clear message - [ ] Error message includes the exceeded depth limit for debugging - [ ] All existing tests pass without modification - [ ] New unit tests cover: - [ ] Normal operation with shallow dicts (depth < 10) - [ ] Normal operation with moderately nested dicts (depth 50-100) - [ ] Proper error handling when max_depth is exceeded - [ ] Custom max_depth parameter works correctly - [ ] Lists containing deeply nested dicts are also protected - [ ] Code coverage remains >= 97% ## Subtasks - [ ] Add `max_depth` parameter to `_redact_dict_inner()` function signature - [ ] Implement depth tracking and validation logic - [ ] Update `redact_dict()` public API to accept optional `max_depth` parameter - [ ] Add comprehensive unit tests for depth limit enforcement - [ ] Update docstrings with depth limit documentation - [ ] Verify no performance regression on typical use cases - [ ] Update CHANGELOG.md with security fix note ## Definition of Done This issue is complete when: 1. The `_redact_dict_inner()` function safely rejects deeply nested structures 2. All unit tests pass (including new depth limit tests) 3. Code coverage remains >= 97% 4. No `RecursionError` can be triggered by any input 5. Documentation clearly explains the depth limit and how to customize it 6. The fix is backward compatible with existing code --- **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#10555
No description provided.