shared/redaction: is_sensitive_key() crashes on non-string dict keys — AttributeError on key.lower() #10573

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

Metadata

Commit: Current HEAD (to be verified)
Branch: main

Background and Context

The is_sensitive_key() function in src/cleveragents/shared/redaction.py (lines 130-142) assumes the key parameter is always a string and calls key.lower() without type checking. However, Python dictionaries can have non-string keys (integers, tuples, etc.). When redact_dict() is called with a dictionary containing non-string keys, the function crashes with an AttributeError.

This is a critical bug that breaks the redaction utility for any code that uses dictionaries with non-string keys.

Expected Behavior

The is_sensitive_key() function should gracefully handle non-string keys by:

  1. Checking if the key is a string before calling .lower()
  2. Returning False for non-string keys (they cannot be sensitive field names)
  3. Allowing redact_dict() to process dictionaries with mixed key types without crashing

Acceptance Criteria

  • is_sensitive_key() accepts non-string keys without raising AttributeError
  • Non-string keys return False from is_sensitive_key()
  • redact_dict() successfully processes dictionaries with integer, tuple, and other non-string keys
  • Existing behavior for string keys is unchanged
  • Unit tests cover non-string key scenarios
  • Test coverage remains >= 97%

Subtasks

  • Add type checking to is_sensitive_key() function
  • Add early return for non-string keys
  • Write unit tests for non-string key handling
  • Verify existing tests still pass
  • Update function docstring if needed

Definition of Done

  • The fix is implemented in src/cleveragents/shared/redaction.py
  • All unit tests pass, including new tests for non-string keys
  • Code coverage remains >= 97%
  • The reproduction case from the issue no longer crashes
  • PR is reviewed and merged to main

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata **Commit:** Current HEAD (to be verified) **Branch:** main ## Background and Context The `is_sensitive_key()` function in `src/cleveragents/shared/redaction.py` (lines 130-142) assumes the key parameter is always a string and calls `key.lower()` without type checking. However, Python dictionaries can have non-string keys (integers, tuples, etc.). When `redact_dict()` is called with a dictionary containing non-string keys, the function crashes with an `AttributeError`. This is a critical bug that breaks the redaction utility for any code that uses dictionaries with non-string keys. ## Expected Behavior The `is_sensitive_key()` function should gracefully handle non-string keys by: 1. Checking if the key is a string before calling `.lower()` 2. Returning `False` for non-string keys (they cannot be sensitive field names) 3. Allowing `redact_dict()` to process dictionaries with mixed key types without crashing ## Acceptance Criteria - [ ] `is_sensitive_key()` accepts non-string keys without raising `AttributeError` - [ ] Non-string keys return `False` from `is_sensitive_key()` - [ ] `redact_dict()` successfully processes dictionaries with integer, tuple, and other non-string keys - [ ] Existing behavior for string keys is unchanged - [ ] Unit tests cover non-string key scenarios - [ ] Test coverage remains >= 97% ## Subtasks - [ ] Add type checking to `is_sensitive_key()` function - [ ] Add early return for non-string keys - [ ] Write unit tests for non-string key handling - [ ] Verify existing tests still pass - [ ] Update function docstring if needed ## Definition of Done - The fix is implemented in `src/cleveragents/shared/redaction.py` - All unit tests pass, including new tests for non-string keys - Code coverage remains >= 97% - The reproduction case from the issue no longer crashes - PR is reviewed and merged to main --- **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#10573
No description provided.