Repository navigation
fix(sdk): mask registered secrets at the tool chokepoint - #4715
alanhuangyoo wants to merge 1 commit into
Conversation
Sweeping openhands-tools for masking call sites returns exactly one file,
terminal/impl.py. The other twelve tool packages hand their output to the
model unmasked, so whether a secret is masked depends on which tool the
model happened to pick:
cat .env via terminal -> MASKED
view .env via file_editor -> RAW
ToolDefinition.__call__ is the one place every tool with an executor
returns through, and it already receives the conversation. Mask there,
against Observation.content, which is the base surface every tool's text
lands in. A tool added later is covered without touching it.
MCPToolDefinition overrides __call__ and masks on its own path; the test
pins that it is the only class allowed to, so a tool that leaves the
chokepoint has to be named deliberately.
terminal/impl.py keeps its own masking: TerminalExecutor is also called
directly, without going through ToolDefinition, and its own test covers
that path. Masking twice is idempotent.
Closes OpenHands#4677
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
|
Superseded by #4788, which landed on 1 Sep and fixes this at the same place. Closing rather than rebasing, because the merged version is the better of the two and the difference is not cosmetic. Both hook
That is right, and it means an observation that renders from its own fields would still have leaked under this PR. Nothing here is worth carrying forward on top of it. Thanks @VascoSch92. |
HUMAN:
Ran the new masking tests plus the existing tool suite; checked a registered secret is masked in the observation content and that an unregistered string is left alone.
AGENT:
Why
Sweeping the tools package for masking call sites returns one file:
Twelve other tool packages hand their output to the model unmasked, so whether a registered secret is masked depends on which tool the model happened to pick.
ToolDefinition.__call__is the one place every tool with an executor returns through, and it already receivesconversation. Masking there covers the whole tool surface instead of the tools that remembered — the property #4677 asks for, so tool #14 is covered by default rather than by remembering.Summary
ToolDefinition.__call__, againstObservation.content— the base field every tool's text lands in, so the masking is not tool-specific.acalldelegates to__call__, so the async path is covered.terminal/impl.pykeeps its own masking:TerminalExecutoris also called directly, without going throughToolDefinition, andtest_terminal_executor_with_conversation_secretscovers exactly that path. Masking twice is idempotent.tests/sdk/tool/test_secret_masking_chokepoint.py, including a structural test that fails when a class starts overridingToolDefinition.__call__without arranging its own masking.Issue Number
Closes #4677
How to Test
End-to-end against a real
Conversationwith a registered secret, no mocks:On
main:On this branch:
Same harness across the tools named in the acceptance criteria, and a call with
conversation=Noneto confirm behaviour is unchanged when there is no registry:Note on the issue text:
grepandglobare listed there next tofile_editor, but both return only file paths, never matched line content —so they are covered by construction rather than because they were leaking.
file_editoris the reproducible leak.Suites:
uv run pytest tests/sdk/tool/ tests/cross/test_agent_secrets_integration.py \ tests/tools/terminal/test_secrets_masking.py -q # 221 passed uv run ruff check && uv run ruff format --check # cleanThe new
test_file_editor_does_not_hand_the_model_a_raw_secretfails onmainwithVideo/Screenshots
Not applicable — no GUI surface; the console transcripts above are the evidence.
Design Doc
Not added; the change is one function and one call site.