Skip to content

Commit 6139e2d

Browse files
Debug Agentclaude
andcommitted
fix: redact sensitive credentials from command logs
Use the existing redact_text_secrets utility to redact sensitive environment variables and credentials (API keys, tokens, etc.) from logged command output. This prevents credentials from appearing in logs when passed to subprocesses via environment variables or command-line arguments. Changes: - Import redact_text_secrets from openhands.sdk.utils.redact - Apply redaction to all logged commands in execute_command() - Leverages existing comprehensive secret detection patterns: - API keys from major providers (OpenAI, Anthropic, HuggingFace, etc.) - Bearer tokens and session tokens - Database and service credentials - URL query parameters with sensitive values Security Impact: - Credentials (LMNR_PROJECT_API_KEY, API keys, tokens) no longer appear in logger output for commands like "docker run", "python", etc. - Prevents leaks to Datadog, CloudWatch, and other log aggregators - Maintains command structure for debugging (shows "KEY=<redacted>") Example: Before: "$ docker run -e LMNR_PROJECT_API_KEY=sk-... -e RUNTIME_API_KEY=..." After: "$ docker run -e LMNR_PROJECT_API_KEY=<redacted> -e RUNTIME_API_KEY=<redacted>" Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 3e0a3a0 commit 6139e2d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

openhands-sdk/openhands/sdk/utils/command.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections.abc import Mapping
77

88
from openhands.sdk.logger import get_logger
9+
from openhands.sdk.utils.redact import redact_text_secrets
910

1011

1112
logger = get_logger(__name__)
@@ -61,11 +62,14 @@ def execute_command(
6162
if isinstance(cmd, str):
6263
cmd_to_run = cmd
6364
use_shell = True
64-
logger.info("$ %s", cmd)
65+
cmd_str = cmd
6566
else:
6667
cmd_to_run = cmd
6768
use_shell = False
68-
logger.info("$ %s", " ".join(shlex.quote(c) for c in cmd))
69+
cmd_str = " ".join(shlex.quote(c) for c in cmd)
70+
71+
# Log the command with sensitive values redacted
72+
logger.info("$ %s", redact_text_secrets(cmd_str))
6973

7074
proc = subprocess.Popen(
7175
cmd_to_run,

0 commit comments

Comments
 (0)