fix(redact): safely handle non-string inputs

redact_sensitive_text() now returns early for None and coerces other
non-string values to str before applying regex-based redaction,
preventing TypeErrors in logging/tool-output paths.

Cherry-picked from PR #2369 by aydnOktay.
This commit is contained in:
aydnOktay 2026-03-21 16:55:02 -07:00 committed by Teknium
parent 52dd479214
commit 40c9a13476
No known key found for this signature in database
2 changed files with 11 additions and 0 deletions

View file

@ -124,6 +124,13 @@ class TestPassthrough:
def test_none_returns_none(self):
assert redact_sensitive_text(None) is None
def test_non_string_input_int_coerced(self):
assert redact_sensitive_text(12345) == "12345"
def test_non_string_input_dict_coerced_and_redacted(self):
result = redact_sensitive_text({"token": "sk-proj-abc123def456ghi789jkl012"})
assert "abc123def456" not in result
def test_normal_text_unchanged(self):
text = "Hello world, this is a normal log message with no secrets."
assert redact_sensitive_text(text) == text