test(redact): add sensitive text redaction

- Introduce a new test suite for the `redact_sensitive_text` function, covering various sensitive data formats including API keys, tokens, and environment variables.
- Ensure that sensitive information is properly masked in logs and outputs while non-sensitive data remains unchanged.
- Add tests for different scenarios including JSON fields, authorization headers, and environment variable assignments.
- Implement a redacting formatter for logging to enhance security during log output.
This commit is contained in:
teknium1
2026-02-28 21:56:25 -08:00
parent 95b0610f36
commit 70dfec9638
2 changed files with 178 additions and 1 deletions

View File

@@ -1037,8 +1037,12 @@ def terminal_tool(
)
output = output[:head_chars] + truncated_notice + output[-tail_chars:]
# Redact secrets from command output (catches env/printenv leaking keys)
from agent.redact import redact_sensitive_text
output = redact_sensitive_text(output.strip()) if output else ""
return json.dumps({
"output": output.strip() if output else "",
"output": output,
"exit_code": returncode,
"error": None
}, ensure_ascii=False)