Repository navigation
fix(security): stop logging runtime command contents - #4280
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
⚠️ QA Report: PASS WITH ISSUES
The agent-server timeout and RemoteWorkspace client paths now avoid logging fake token-shaped command contents, but a real terminal execution path still emits command/output contents through lower-level DEBUG logs.
Does this PR achieve its stated goal?
Partially. I verified the main agent-server timeout path with a real local server and HTTP request: the base branch logged the full timed-out command with a fake token, while the PR logged only timeout metadata and command ID, and the cleanup trap still ran. I also verified RemoteWorkspace command execution against a local agent-server no longer logs the command on the client side. However, a real SubprocessTerminal command execution on the PR still captured the fake token in DEBUG logs from the terminal backend, so the broader goal of stopping runtime command/output logging is not fully achieved.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully. |
| CI Status | ⏳ 21 successful, 2 skipped, 6 pending, 0 failing at the time checked. |
| Functional Verification |
Functional Verification
Test 1: agent-server timeout logging through the real HTTP API
Step 1 — Reproduce baseline without the fix:
Checked out 14876fc971807314240b6e74158baba8f25307dd, started uv run python -m openhands.agent_server --host 127.0.0.1 --port 8123, then POSTed a token-shaped command to /api/bash/start_bash_command with timeout: 1.
Observed:
[base] http_status=200 timed_out_log=yes marker_exists=yes log_contains_fake_token=yes
[base] relevant log lines:
"Command timed out after 1 seconds: LEAK_TEST=<FAKE_TOKEN>; trap 'touch /tmp/qa-base-cleanup-marker; exit 0' TERM; sleep 30"
This confirms the bug: the command timed out, cleanup still ran, and the timeout log included the fake token-bearing command.
Step 2 — Apply the PR changes:
Checked out 51d40fb6602785954c36056f06790ffd1cf17bb4.
Step 3 — Re-run with the fix in place:
Started uv run python -m openhands.agent_server --host 127.0.0.1 --port 8124 and sent the same kind of request.
Observed:
[pr] http_status=200 timed_out_log=yes marker_exists=yes log_contains_fake_token=no
[pr] relevant log lines:
"Command timed out after 1 seconds (command_id=02dde4ce-2ead-4b89-9d5f-6427b46c796e)"
This confirms the agent-server timeout path preserves behavior while removing the command contents from the log.
Test 2: RemoteWorkspace client command logging against a local server
Step 1 — Reproduce baseline without the fix:
Checked out the base commit, started a local agent-server, and ran:
RemoteWorkspace(host="http://127.0.0.1:8125", working_dir="/tmp").execute_command("printf '<FAKE_TOKEN>\n'", timeout=10.0)Observed:
[base-remote] exit_code=0
[base-remote] result_contains_fake_token=True
[base-remote] client_log_contains_fake_token=True
[base-remote] relevant client log lines:
Executing remote command: printf '<FAKE_TOKEN>
This shows the result returned command output as expected, but the client DEBUG log exposed the command.
Step 2 — Apply the PR changes:
Checked out the PR commit.
Step 3 — Re-run with the fix in place:
Ran the same RemoteWorkspace command against a local agent-server on port 8126.
Observed:
[pr-remote] exit_code=0
[pr-remote] result_contains_fake_token=True
[pr-remote] client_log_contains_fake_token=False
[pr-remote] relevant client log lines:
Executing remote command
This confirms the RemoteWorkspace path still executes successfully and no longer logs the command contents on the client side.
Test 3: real SubprocessTerminal command logging
Step 1 — Reproduce baseline without the fix:
Checked out the base commit and executed a real shell command through TerminalSession(SubprocessTerminal(...)) with DEBUG log capture.
Observed:
[base-terminal] exit_code=0
[base-terminal] returned_observation_contains_fake_token=True
[base-terminal] captured_debug_logs_contain_fake_token=True
RECEIVED ACTION: command="printf '<FAKE_TOKEN>
'" ...
SENDING COMMAND: "printf '<FAKE_TOKEN>
'"
Wrote to subprocess PTY: b"printf '<FAKE_TOKEN>
'
"
Read from subprocess PTY: ... printf '<FAKE_TOKEN> ... <FAKE_TOKEN> ...
COMBINED OUTPUT: printf '<FAKE_TOKEN> ... <FAKE_TOKEN>
This confirms the old terminal path logged command and output contents.
Step 2 — Apply the PR changes:
Checked out the PR commit.
Step 3 — Re-run with the fix in place:
Ran the same real SubprocessTerminal execution with a different fake token.
Observed:
[pr-terminal] exit_code=0
[pr-terminal] returned_observation_contains_fake_token=True
[pr-terminal] captured_debug_logs_contain_fake_token=True
Received terminal action (is_input=False, command_length=48)
Initial terminal output (content_length=269)
Sending command (command_length=48)
Wrote to subprocess PTY: b"printf '<FAKE_TOKEN>
'
"
Read from subprocess PTY: ... printf '<FAKE_TOKEN> ... <FAKE_TOKEN> ...
Terminal content read (content_length=642)
This shows the TerminalSession log lines were redacted to lengths, but the same real execution still emits raw command/output through the lower-level subprocess terminal logs.
Issues Found
- 🟠 Issue: Real
SubprocessTerminalexecution still logs command and terminal output contents at DEBUG level, so the terminal-runtime portion of the secret-log fix is incomplete.
This review was created by an AI agent (OpenHands) on behalf of the user.
Mutation-testing the new suiteI ran mutation testing against the five test files this PR touches to see which of the scrubbed log sites are actually pinned down. Baseline: 64 passed. The test pattern here is the right one — plant a known secret, exercise the code, then assert both that the log line still exists and that the secret doesn't appear in
Four mutants survive with a fully green suite. Three of them share a shape: every covered log site is on a success or timeout path, and none of the exception handlers are exercised.
1. The exception handlers are the least-tested and most leak-prone sites
def test_execute_command_generator_exception_handling(caplog):
secret = "ghp_" + "e" * 36
caplog.set_level(logging.DEBUG)
# ... existing setup, with the command carrying the secret ...
generator = mixin._execute_command_generator(
f"curl -H 'Authorization: Bearer {secret}' example.test", None, 30.0
)
# ... existing assertions ...
assert "Remote command execution failed" in caplog.text
assert secret not in caplog.textFor The SIGKILL-failed branch ( 2. The one behaviour change in the PR is untestedNarrowing What the narrowing actually prevents is a bash payload that carries @pytest.mark.asyncio
async def test_bash_socket_runs_command_payload_that_declares_auth_type():
"""A bash payload carrying type="auth" must still execute, not be skipped."""
ws = _make_mock_websocket(headers={})
ws.receive_json.side_effect = [
{"type": "auth", "command": "printf hi"},
WebSocketDisconnect(),
]
mock_bash_service = MagicMock(spec=BashEventService)
mock_bash_service.subscribe_to_events = AsyncMock(return_value=uuid4())
mock_bash_service.unsubscribe_from_events = AsyncMock(return_value=True)
mock_bash_service.start_bash_command = AsyncMock()
with (
patch("openhands.agent_server.sockets.bash_event_service", mock_bash_service),
patch("openhands.agent_server.sockets.get_default_config") as mock_config,
):
mock_config.return_value.session_api_keys = []
await bash_events_socket(
ws, session_api_key=None, resend_mode=None, resend_all=False
)
mock_bash_service.start_bash_command.assert_awaited_once()
assert mock_bash_service.start_bash_command.await_args.args[0].command == "printf hi"A matching negative — Not a test gap: the strongest fix in this PR isn't a testDropping the On the lint angle — ruff's One last thing worth checking before merge: This comment was generated by an AI assistant on behalf of the user. |
Co-authored-by: openhands <openhands@all-hands.dev>
|
Addressed the review feedback in
|
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Runtime logging behavior was verified before/after with real terminal, agent-server HTTP, and RemoteWorkspace execution paths; the PR stops leaking token-shaped command/output contents to logs while preserving command execution.
Does this PR achieve its stated goal?
Yes. The stated goal was to stop logging runtime command contents without breaking command execution, timeout signaling, or returned results. On origin/main, the same real operations leaked fake token-shaped values into terminal, server timeout, and remote workspace logs; on PR commit 5f577c9, those operations still returned/produced the expected user output and timeout side effect, but the logs only included metadata such as command IDs, lengths, and markers.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv run python -V created the project environment and installed editable packages successfully. |
| CI Status | 🟡 Most checks are successful; Docker image builds and coverage were still in progress when checked; qa-changes is skipped. |
| Functional Verification | ✅ Real runtime paths verified: terminal subprocess, agent-server bash HTTP timeout, and SDK RemoteWorkspace command execution. |
Functional Verification
Test 1: Terminal subprocess logs no longer include command/output contents
Step 1 — Reproduce baseline without the fix:
Checked out origin/main (395b94b0) and ran a real subprocess terminal command through TerminalSession:
observation_contains_secret=True
log_contains_secret=True
wrote_marker=True
read_marker=True
observation_exit_code=0
This confirms the old behavior leaked the fake token-shaped command/output value to debug logs while the terminal command itself succeeded.
Step 2 — Apply the PR's changes:
Checked out fix-sensitive-runtime-logs at 5f577c9af074b0b5fcbbd70f4a2ae0cdc1fbbb56.
Step 3 — Re-run with the fix in place:
Ran the same terminal execution path:
observation_contains_secret=True
log_contains_secret=False
wrote_marker=True
read_marker=True
observation_exit_code=0
This shows user-visible command behavior is preserved, but terminal debug logs no longer contain the fake secret.
Test 2: Agent-server bash timeout logs no longer include command contents
Step 1 — Reproduce baseline without the fix:
Started agent-server from origin/main, made a real HTTP request to /api/bash/start_bash_command with a timeout command that installs a SIGTERM trap, and waited for timeout handling:
200
marker_exists=true
server_log_contains_bash_secret=true
Command timed out after 1 seconds: LEAK_TEST=ghp_BASEBASH...; trap 'touch /tmp/qa_marker_BASE; exit 0' TERM; sleep 30
This confirms the timeout path worked, the cleanup trap ran, and the old server warning log included raw command contents.
Step 2 — Apply the PR's changes:
Checked out the PR branch and started agent-server on a fresh port.
Step 3 — Re-run with the fix in place:
Sent the same HTTP timeout scenario:
200
marker_exists=true
server_log_contains_bash_secret=false
Command timed out after 1 seconds (command_id=f6e72669-8884-45ca-ac5b-1a4c084857cf)
This confirms timeout signaling and SIGTERM cleanup still work, while the timeout log now uses the command ID instead of raw command contents.
Test 3: RemoteWorkspace command logs no longer include command contents
Step 1 — Reproduce baseline without the fix:
With the base agent-server running, executed a real SDK RemoteWorkspace.execute_command(...) call against the server:
stdout_contains_secret=True
stderr_contains_timeout=False
exit_code=0
log_contains_secret=True
log_has_remote_marker=True
This confirms the old RemoteWorkspace client log included the fake token-shaped command content even though the remote command succeeded.
Step 2 — Apply the PR's changes:
Checked out the PR branch and ran the same SDK client against a fresh local server.
Step 3 — Re-run with the fix in place:
Executed the same RemoteWorkspace call:
stdout_contains_secret=True
stderr_contains_timeout=False
exit_code=0
log_contains_secret=False
log_has_remote_marker=True
This shows returned command output is preserved for the caller, but the RemoteWorkspace log no longer leaks the command contents.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Runtime QA confirms the PR preserves command execution results while stopping sensitive command/terminal content from appearing in the affected debug/warning logs.
Does this PR achieve its stated goal?
Yes. The PR set out to stop logging runtime command contents that may contain credentials; I reproduced the pre-fix leak on the baseline commit, then reran the same real runtime paths on the PR. The bash timeout path still returns 200 OK and times out, RemoteWorkspace and terminal commands still return the secret in user-facing command results, but the captured runtime logs no longer contain the secret-shaped values or raw command text.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv sync --dev completed successfully; branch restored to fix-sensitive-runtime-logs with a clean worktree. |
| CI Status | ⏳ 39 checks observed: 33 passing, 5 skipped, 1 pending (qa-changes, this workflow). |
| Functional Verification | ✅ Verified bash API timeout logs, RemoteWorkspace logs, terminal subprocess logs, and bash websocket redundant auth handling with real runtime operations. |
Functional Verification
Test 1: Bash API timeout logging no longer includes raw command contents
Step 1 — Reproduce baseline leak without the fix:
Checked out baseline commit 395b94b0c3c4994f6c530f1e3bf3196f71fab950, started the agent-server on port 8766, and sent a real timeout command containing a fake token-shaped value to POST /api/bash/start_bash_command.
Observed HTTP/1.1 200 OK; the baseline server log then included the raw command:
Command timed out after 1 seconds: LEAK_TEST=ghp_QABASEBASEBASEBASEBASEBASEBASEBASEBASEBA; trap 'echo cleanup-ran >&2; exit 0' TERM; sleep 20
This confirms the original bug: the timeout warning exposed the full command and fake credential-shaped value.
Step 2 — Apply the PR changes:
Checked out PR head 5f577c9af074b0b5fcbbd70f4a2ae0cdc1fbbb56 and started the agent-server on port 8767.
Step 3 — Re-run with the fix in place:
Sent the same kind of real timeout command to the PR server. Observed HTTP/1.1 200 OK; the PR server log only included metadata:
Command timed out after 1 seconds (command_id=88e66e5c-01ab-4e66-b298-388bf4fd4bb7)
This confirms the timeout path still works, but the runtime warning no longer logs command contents or the fake token.
Test 2: RemoteWorkspace preserves command output but omits command text from client logs
Step 1 — Reproduce baseline leak without the fix:
Against the baseline server on port 8766, I ran a real SDK RemoteWorkspace.execute_command() call with a fake token-shaped value.
Observed:
result_exit_code= 0
result_contains_secret= True
logs_contain_secret= True
DEBUG:openhands.sdk.workspace.remote.remote_workspace_mixin:Executing remote command: printf 'ghp_QAREMOTEBASEBASEBASEBASEBASEBASEBASE\n'
This confirms baseline RemoteWorkspace logging exposed the command text even though the command itself executed correctly.
Step 2 — Apply the PR changes:
Used the PR server on port 8767 and the same RemoteWorkspace API path.
Step 3 — Re-run with the fix in place:
Ran the equivalent command on PR code:
result_exit_code= 0
result_contains_secret= True
logs_contain_secret= False
DEBUG:openhands.sdk.workspace.remote.remote_workspace_mixin:Executing remote command
This shows user-facing command output is preserved, but the DEBUG log no longer includes the secret-bearing command.
Test 3: Subprocess terminal preserves output but omits command/output content from debug logs
Step 1 — Reproduce baseline leak without the fix:
On baseline, I created a real subprocess terminal session and executed printf with a fake token-shaped value. The command result contained the value, and DEBUG logs also contained it:
observation_contains_secret= True
logs_contain_secret= True
DEBUG:openhands.tools.terminal.terminal.terminal_session:SENDING COMMAND: "printf 'ghp_QATERMBASEBASEBASEBASEBASEBASEBASEBASE\n'"
DEBUG:openhands.tools.terminal.terminal.subprocess_terminal:Read from subprocess PTY: '... ghp_QATERMBASEBASEBASEBASEBASEBASEBASEBASE ...'
This confirms the baseline terminal path leaked both command and terminal content through debug logging.
Step 2 — Apply the PR changes:
Checked out PR head and reran the same subprocess terminal workflow.
Step 3 — Re-run with the fix in place:
Observed:
observation_contains_secret= True
logs_contain_secret= False
DEBUG:openhands.tools.terminal.terminal.subprocess_terminal:Wrote to subprocess PTY (byte_count=285)
DEBUG:openhands.tools.terminal.terminal.terminal_session:Sending command (command_length=50)
DEBUG:openhands.tools.terminal.terminal.subprocess_terminal:Read from subprocess PTY (content_length=747)
This confirms the terminal still returns the expected command output to the user, while debug logs now contain only lengths/counts.
Test 4: Bash websocket ignores redundant auth control frame and still executes commands
On PR code, I connected to the real /sockets/bash-events websocket, sent a redundant auth control frame containing a fake sk-oh-... value, then sent a bash command:
saw_command_event= True
saw_output_event= True
Server log grep for the fake auth value, validation errors, and command output showed only the normal request marker:
Received bash request
This confirms the changed websocket path accepts the real command after a redundant auth frame without logging the auth secret.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
Final verdict: PASS
all-hands-bot
left a comment
There was a problem hiding this comment.
Review verdict: material security finding
The primary timeout, execution-error, RemoteWorkspace, and terminal/subprocess paths are correctly changed to log metadata rather than command/output content, and the added regression coverage exercises those normal paths well. Current GitHub checks are green. I also ran the five changed test modules: 109 tests passed; the remaining 33 failures were all pre-existing tmux-parameterized cases because tmux is unavailable in this review environment.
Important finding
openhands-agent-server/openhands/agent_server/sockets.py:548-558 still logs the complete BashEventBase representation whenever a bash WebSocket event send is skipped or fails:
skip_sending_bash_event_socket_disconnected: %rerror_sending_bash_event_disconnected: %r (%s)error_sending_bash_event: %r
BashCommand.__repr__ contains the raw command, while BashOutput.__repr__ contains raw stdout/stderr. I reproduced this on the checked-out head by making websocket.send_json() raise RuntimeError: a token-shaped value in BashOutput.stdout appeared verbatim in the DEBUG log. A disconnect/send failure is a realistic production condition, so the stated security goal remains incomplete even though the successful-send path is clean.
Please change these messages to log only safe metadata (for example event kind/id, command_id, order, exit code, and exception type), and add a regression test that injects token-shaped command/output content and forces _send_bash_event() through both the disconnected and unexpected-exception paths. This location is not part of a changed hunk, so I am reporting it in the review body rather than creating an invalid inline thread.
Risk assessment
High security risk until addressed. The leak requires a WebSocket disconnect/send exception, but when triggered it can disclose exactly the command and terminal output this PR intends to keep out of centralized logs. The functional behavior changes also touch terminal execution/stdin/stdout handling, so per repository policy a human maintainer should make the final merge decision after the lightweight eval assessment.
This review was created by an AI agent (OpenHands) on behalf of the repository reviewer.
enyst
left a comment
There was a problem hiding this comment.
Interesting, it looks like this comment is correct? #4280 (review)
Co-authored-by: openhands <openhands@all-hands.dev>
|
Fixed the WebSocket send-failure leak in
Added regression coverage with token-shaped command, stdout/stderr, and exception-message values. All 92 relevant security tests and pre-commit checks pass. |
enyst
left a comment
There was a problem hiding this comment.
👋 I'm an AI agent (Opus 5) reviewing this PR on behalf of Engel Nyst (@enyst).
🟢 Good taste
This removes command, input, output, event-repr, and exception-text leakage at the relevant runtime boundaries while retaining useful identifiers, lengths, timeout values, and exception types for diagnosis. The regression tests use sentinel secrets across bash service, websocket, remote workspace, subprocess terminal, and terminal session paths. I did not find a remaining leak introduced or missed within this PR's changed surfaces.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🔴 HIGH
The patch is mechanically small but directly changes secrets-handling and production diagnostic behavior across several shared runtime layers. A missed sink would expose user commands or output; over-redaction could impair incident diagnosis.
Recommendation: Do not auto-merge. Request review from a human security/runtime maintainer to validate coverage of logging sinks and the diagnostic tradeoff.
VERDICT:
✅ Worth merging: The redaction strategy is consistent and backed by focused regression coverage.
KEY INSIGHT:
Structured metadata such as command IDs, byte counts, and exception types preserves operational value without serializing user-controlled content.
|
🤖 OpenHands is reviewing this PR. Requested reviewer: This comment was posted by an AI agent (OpenHands). |
There was a problem hiding this comment.
🟡 Acceptable, but incomplete security fix
The metadata-only changes for bash execution, RemoteWorkspace, terminal sessions, subprocess PTY I/O, and bash-event delivery are consistent and preserve returned command results. The focused regression tests cover the primary success, timeout, and send-failure paths. I reviewed commit b54af3bbba3a06afadb4c6ea01e07d0e83c7acc7; its CI checks were green apart from the then-running QA job. Locally, 129 focused tests passed; 33 tmux-parameterized failures were environmental because tmux is unavailable.
[IMPORTANT FINDING]
openhands-agent-server/openhands/agent_server/sockets.py:468: the bash WebSocket exception handler still callslogger.exception("error_in_bash_event_subscription", stack_info=True). This serializesstr(e)into centralized logs. For Pydantic validation failures, that string includes the rejected input value. I reproduced this throughbash_events_socketwithcommand={"credential": "token-SECRET123"}; the captured ERROR traceback containedtoken-SECRET123verbatim. The same handler also catches exceptions fromstart_bash_command, whose messages may contain command text. This leaves a realistic authenticated runtime path that defeats the stated security goal. Please log safe metadata only, for exampleerror_typeand a command ID when one exists, rather than exception text or traceback on this path. Add a regression test that submits a malformed secret-bearing bash payload and asserts the sentinel is absent fromcaplog.text.
I am placing this in the review body because line 468 itself is not an added line in the PR diff.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🔴 HIGH
This is a security-focused change across shared runtime command and terminal paths. Most known sinks are addressed, but the confirmed WebSocket validation/error sink can still disclose client-controlled credential material. The terminal execution changes can also plausibly affect evaluation behavior, so a human runtime/security maintainer should make the final merge decision after the lightweight eval assessment.
VERDICT:
❌ Needs follow-up: remove the remaining exception-text sink before merging.
KEY INSIGHT:
Exception tracebacks are payload logs when validation errors embed rejected user input.
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add or edit
.agents/skills/custom-codereview-guide.mdwith the/codereviewtrigger and the missing repository context.- Re-request a review so the reviewer reads the updated guidance from the PR branch.
- Let the guideline change go through normal maintainer review when merged.
Resolve with AI? Install the iterate skill and run
/iterateto drive CI, review, and QA.Was this review helpful? React with 👍 or 👎.
This review was created by an AI agent (OpenHands) on behalf of the repository reviewer.
all-hands-bot
left a comment
There was a problem hiding this comment.
⚠️ QA Report: PASS WITH ISSUES
Runtime verification passed: the PR stops app/runtime debug logs from recording fake credential-bearing command contents while preserving command execution, timeout handling, terminal output, and bash websocket behavior.
Does this PR achieve its stated goal?
Yes. I reproduced the sensitive-log problem on the merge-base baseline (395b94b0) and re-ran the same runtime scenarios on the current PR head (069e30a2): bash timeout execution still returned normally and ran the SIGTERM cleanup trap, terminal execution still returned the fake secret to the caller, and the app/runtime logs no longer contained the fake secret. I also verified the remote workspace command generator no longer logs the full command, and a redundant bash websocket auth frame no longer blocks the following real command.
| Phase | Result |
|---|---|
| Environment Setup | ✅ Used the repo's uv run environment to start a real local agent-server with DEBUG app logging and run SDK/tool clients. |
| CI Status | sdk-tests), and 5 skipped; I did not rerun tests per QA instructions. |
| Functional Verification | ✅ Sensitive runtime log paths exercised before/after with fake token-shaped inputs; changed behavior works. |
Functional Verification
Test 1: agent-server bash timeout log no longer includes command contents
Step 1 — Reproduce baseline without the fix:
Checked out 395b94b0, started a real local agent-server, and sent POST /api/bash/start_bash_command with a command shaped like:
LEAK_TEST=<FAKE_SECRET>; trap 'touch /tmp/qa_cleanup_BASE2; exit 0' TERM; sleep 30Baseline summary:
{
"http_status": 200,
"http_kind": "BashCommand",
"server_timeout_logged": true,
"server_cleanup_marker_exists": true,
"server_secret_in_logs": true,
"server_log_excerpt": [
"Command timed out after 1 seconds: LEAK_TEST=<FAKE_SECRET>; trap 'touch /tmp/qa_cleanup_BASE2; exit 0' TERM; sleep 30"
]
}This confirms the original bug: the server logged the full timed-out command, including credential-shaped content, while still running the cleanup trap.
Step 2 — Apply the PR's changes:
Checked out current PR head 069e30a2 and reran the same scenario.
Step 3 — Re-run with the fix in place:
PR-head summary:
{
"http_status": 200,
"http_kind": "BashCommand",
"server_timeout_logged": true,
"server_cleanup_marker_exists": true,
"server_secret_in_logs": false,
"server_log_excerpt": [
"Command timed out after 1 seconds (command_id=a9c54ee0-13ec-4d27-b6fe-47997b55d15d)"
]
}This shows the timeout path still behaves correctly, but the log now contains metadata instead of the sensitive command.
Test 2: terminal debug logs no longer include typed commands or terminal output
Step 1 — Reproduce baseline without the fix:
On 395b94b0, created a real TerminalSession using the subprocess terminal and executed:
printf '<FAKE_SECRET>\n'Baseline summary:
{
"terminal_observation_has_secret": true,
"terminal_secret_in_logs": true,
"terminal_log_excerpt": [
"SENDING COMMAND: \"printf '<FAKE_SECRET>\\n'\"",
"Wrote to subprocess PTY: b\"printf '<FAKE_SECRET>\\n'\\n\"",
"Read from subprocess PTY: ... <FAKE_SECRET> ..."
]
}This confirms the old runtime logs captured both the command and terminal output.
Step 2 — Apply the PR's changes:
Checked out 069e30a2 and reran the same terminal operation.
Step 3 — Re-run with the fix in place:
PR-head summary:
{
"terminal_observation_has_secret": true,
"terminal_secret_in_logs": false,
"terminal_log_excerpt": [
"Received terminal action (is_input=False, command_length=51)",
"Sending command (command_length=51)",
"Wrote to subprocess PTY (byte_count=52)",
"Read from subprocess PTY (content_length=749)"
]
}This confirms user-visible terminal behavior is preserved while logs now expose only lengths/counts.
Test 3: remote workspace command generator no longer logs full commands
Step 1 — Reproduce baseline without the fix:
On 395b94b0, invoked RemoteWorkspace._execute_command_generator(...) with:
curl -H 'Authorization: Bearer <FAKE_SECRET>' https://example.invalidBaseline log probe:
{'secret_in_log': True, 'excerpt': "DEBUG:openhands.sdk.workspace.remote.remote_workspace_mixin:Executing remote command: curl -H 'Authorization: Bearer <FAKE_SECRET>' https://example.invalid\n"}
This confirms the remote command path logged credential-bearing command text at DEBUG.
Step 2 — Apply the PR's changes:
Checked out 069e30a2 and reran the same generator probe.
Step 3 — Re-run with the fix in place:
PR-head log probe:
{'secret_in_log': False, 'excerpt': 'DEBUG:openhands.sdk.workspace.remote.remote_workspace_mixin:Executing remote command\n'}
This confirms the changed remote path no longer logs the command contents.
Test 4: redundant bash websocket auth frame no longer blocks a real command
Step 1 — Reproduce baseline without the fix:
On 395b94b0, connected to /sockets/bash-events, sent a redundant auth control frame, then sent a real bash command (printf ws-ok).
Baseline websocket summary:
{
"event_count": 1,
"saw_error": true,
"saw_ws_ok": false,
"excerpt": "BashError ... Field required ... input_value={'type': 'auth', ...}"
}This shows the auth frame was treated as a bash request and prevented the real command from being accepted.
Step 2 — Apply the PR's changes:
Checked out 069e30a2 and repeated the websocket interaction.
Step 3 — Re-run with the fix in place:
PR-head websocket summary:
{
"event_count": 1,
"saw_error": false,
"saw_ws_ok": true,
"secret_in_ws_payloads": false,
"excerpt": "{\"command\":\"printf ws-ok\", ... ,\"kind\":\"BashCommand\"}"
}This confirms the changed websocket loop ignores the redundant auth frame and processes the next command.
Issues Found
- 🟠 CI: Current GitHub checks show
sdk-testsfailing. I did not rerun or diagnose tests, but the PR is not fully green at the time of this QA review. - No functional issues found in the runtime scenarios I exercised.
Final verdict: PASS WITH ISSUES.
This review was created by an AI agent (OpenHands) on behalf of the user.
Co-authored-by: openhands <openhands@all-hands.dev>
|
🤖 OpenHands is reviewing this PR. Requested reviewer: This comment was posted by an AI agent (OpenHands). |
all-hands-bot
left a comment
There was a problem hiding this comment.
⚠️ QA Report: PASS WITH ISSUES
The changed runtime paths were exercised before/after with fake credential-bearing commands; the PR preserves command execution/results while removing those values from captured logs, but two CI checks are currently failing.
Does this PR achieve its stated goal?
Yes. I reproduced the original behavior on origin/main: live bash API timeout logs, RemoteWorkspace client logs, and subprocess terminal debug logs all exposed fake token-shaped command/output content. Re-running the same real user flows on fix-sensitive-runtime-logs showed the commands still executed and returned their output to the caller, while captured logs contained only command IDs/lengths/type metadata and LOG_SECRET_HITS=0.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no tests/linters/pre-commit hooks were run. |
| CI Status | sdk-tests and windows-tests are failing; QA Changes by OpenHands is pending; most other checks pass. |
| Functional Verification | ✅ Live bash API, SDK RemoteWorkspace, and subprocess terminal paths verified before/after. |
Functional Verification
Test 1: Live bash API timeout logging
Step 1 — Reproduce / establish baseline (without the fix):
Checked out origin/main, started the real agent server with uv run python -m openhands.agent_server --host 127.0.0.1 --port 18765, then posted a real bash command with a fake credential-shaped value and a 1-second timeout:
curl -H 'Content-Type: application/json' \
--data '{"command":"LEAK_TEST=<fake-ghp-token>; trap ... TERM; sleep 30","timeout":1}' \
http://127.0.0.1:18765/api/bash/start_bash_commandObserved:
BRANCH=main
HTTP_CODE=200
MARKER=present
TIMEOUT_LOG_LINES=1
SECRET_LOG_HITS=1
RESPONSE={"command":"LEAK_TEST=<fake-ghp-token>; trap ... TERM; sleep 30", ...}
LOG: Command timed out after 1 seconds: LEAK_TEST=<fake-ghp-token>; trap ... TERM; sleep 30
This confirms the bug exists on main: the server executed the command and ran the SIGTERM cleanup trap, but the timeout warning logged the full command contents.
Step 2 — Apply the PR's changes:
Checked out fix-sensitive-runtime-logs at 712692cd616cba88f0124c55b2162ed808f0bca8.
Step 3 — Re-run with the fix in place:
Started the real agent server on port 18766 and posted the same kind of timeout command.
Observed:
BRANCH=pr
HTTP_CODE=200
MARKER=present
TIMEOUT_LOG_LINES=1
SECRET_LOG_HITS=0
RESPONSE={"command":"LEAK_TEST=<fake-ghp-token>; trap ... TERM; sleep 30", ...}
LOG: Command timed out after 1 seconds (command_id=f8d5c7e3-d4c5-43d3-9801-ede993e8dfec)
This shows the timeout behavior and returned command payload are preserved for the client, while the server log no longer includes the fake credential-bearing command.
Test 2: SDK RemoteWorkspace client logging against a live server
Step 1 — Reproduce / establish baseline (without the fix):
On origin/main, started a real agent server on port 18767 and used the public SDK client:
workspace = RemoteWorkspace(working_dir=os.getcwd(), host="http://127.0.0.1:18767")
result = workspace.execute_command("printf '<fake-ghp-token>\n'", timeout=10.0)Observed:
BRANCH=main
RESULT_EXIT=0
STDOUT_HAS_SECRET=True
LOG_SECRET_HITS=1
LOG: Executing remote command: printf <fake-ghp-token>
This confirms the client returned the command output correctly, but also leaked the command contents at debug level.
Step 2 — Apply the PR's changes:
Checked out fix-sensitive-runtime-logs at 712692cd616cba88f0124c55b2162ed808f0bca8.
Step 3 — Re-run with the fix in place:
Started a real agent server on port 18768 and ran the same SDK RemoteWorkspace.execute_command(...) flow.
Observed:
BRANCH=pr
RESULT_EXIT=0
STDOUT_HAS_SECRET=True
LOG_SECRET_HITS=0
LOG: Executing remote command
This shows normal RemoteWorkspace command execution still works and returns stdout to the caller, but the debug log no longer contains the command/token value.
Test 3: Subprocess terminal command/output logging
Step 1 — Reproduce / establish baseline (without the fix):
On origin/main, used the public terminal API as a real caller would:
session = create_terminal_session(work_dir=os.getcwd(), terminal_type="subprocess")
session.initialize()
observation = session.execute(TerminalAction(command="printf '<fake-ghp-token>\n'"))
session.close()Observed:
BRANCH=main
OBS_EXIT=0
OBS_HAS_SECRET=True
LOG_SECRET_HITS=11
LOG: RECEIVED ACTION: command='printf <fake-ghp-token>\\n' ...
LOG: SENDING COMMAND: 'printf <fake-ghp-token>'
LOG: Wrote to subprocess PTY: b'printf <fake-ghp-token>\\n'
LOG: COMBINED OUTPUT: printf <fake-ghp-token> ...
This confirms the old terminal path returned the command output but also logged command/output content in several debug messages.
Step 2 — Apply the PR's changes:
Checked out fix-sensitive-runtime-logs at 712692cd616cba88f0124c55b2162ed808f0bca8.
Step 3 — Re-run with the fix in place:
Ran the same subprocess terminal scenario.
Observed:
BRANCH=pr
OBS_EXIT=0
OBS_HAS_SECRET=True
LOG_SECRET_HITS=0
LOG: Read from subprocess PTY (content_length=328)
LOG: Read from subprocess PTY (content_length=748)
This shows the user-facing observation still contains the command output, while debug logs avoid the sensitive command/output content.
Issues Found
- 🟠 Issue: CI is not fully green:
sdk-testsandwindows-testsare currently failing, and the QA check was still pending when reviewed. I did not rerun tests per QA instructions.
This review was created by an AI agent (OpenHands) on behalf of the user.
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste — no material code findings
The change consistently replaces command, terminal-content, event-representation, and exception-text logging with bounded metadata while preserving command results and WebSocket error responses. The previously confirmed bash WebSocket validation-error leak is fixed at head 712692cd616cba88f0124c55b2162ed808f0bca8, and the new tests cover malformed payloads plus error-send failures without allowing token-shaped values into captured logs.
I also reviewed the PR discussion, existing reviews, all 11 changed files, and the surrounding runtime paths. The focused local run exercised 164 tests: 131 passed, including every changed security regression; the 33 failures were only the existing tmux parametrizations because tmux is unavailable in this environment. GitHub currently reports agent-server-tests, tools-tests, workspace-tests, cross-tests, stress tests, binary builds, and QA as successful. sdk-tests and windows-tests remain failed, so maintainers should require those checks to be green or explicitly classify them as unrelated before merging.
Because this touches terminal/stdin/stdout handling, repository policy requires a COMMENT rather than an approval without benchmark evidence. A human runtime maintainer should make the final merge decision after the lightweight eval assessment.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This is a security-sensitive change across shared command execution and terminal paths. The implementation is narrowly scoped, preserves returned data, and has strong leak-regression coverage; residual risk comes from the breadth of runtime logging paths, the terminal-behavior eval category, and two currently failing CI jobs.
VERDICT:
✅ Worth merging once CI/eval validation is accepted by a human maintainer.
KEY INSIGHT:
Logging exception classes and stable identifiers retains operational diagnostics without turning validation errors or runtime events into secret-bearing payload logs.
This review was created by an AI agent (OpenHands) on behalf of the repository reviewer.
|
@VascoSch92 can you kindly re-review? :) CI erros are unrelated |
|
@simonrosenberg For me is good. But why the tests are not passing? |
unrelated CI issue I fixed independently :) |
|
@VascoSch92 thanks for the review! |
…ershell spawns Use psutil.Process.wait/pid_exists for the child liveness wait rather than spawning a fresh powershell.exe on every poll, which itself could exhaust the old 20s watchdog on a slow hosted runner (second failure mode observed in PR #4280). Raise the pytest timeout to 45s to cover the bounded slow path plus finally cleanup. Note in the docstring that the assertion covers only the directly spawned child, not the whole process tree. Co-authored-by: openhands <openhands@all-hands.dev>
HUMAN:
stop logging runtime command contents
AGENT:
Why
Production runtime paths logged complete shell commands and terminal output. Those fields can contain injected credentials. A seven-day production log review found 995 timeout records from the affected path with credential-bearing commands.
Summary
Issue Number
N/A
How to Test
Video/Screenshots
N/A. This changes server-side logging only.
Type
Notes
No secret values or production log payloads are included in this PR.
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:95a1bb6-pythonRun
All tags pushed for this build
About Multi-Architecture Support
95a1bb6-python) is a multi-arch manifest supporting both amd64 and arm6495a1bb6-python-amd64) are also available if needed