Repository navigation
fix(secrets): opt base64 payloads out of secret masking - #5226
jpshackelford wants to merge 1 commit into
Conversation
The recursive masker in SecretRegistry.mask_secrets_in_model ran a substring .replace across every string field on every observation. A registered secret whose characters happened to appear inside a large opaque blob — screenshots are hundreds of KB of base64 and collide with any 8+ char token by chance — got <secret-hidden> spliced mid-payload. The corrupted observation was persisted, so every subsequent turn rebuilt the same poisoned tool_result and the provider rejected the whole conversation as invalid base64. Add SkipSecretMasking, a marker for Annotated[T, SkipSecretMasking()] that _mask_model skips. Tag BrowserObservation.screenshot_data and ImageContent.image_urls with it so both the raw blob and the data URL rendered from it round-trip byte-for-byte through the masker. The tag lives in openhands.sdk.utils so both the masker and the models it walks can reference it without a cycle. Fixes #5224. Co-authored-by: openhands <openhands@all-hands.dev>
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Code Review Roasted Output
Taste: good.
Small, focused fix that matches the issue's preferred remedy: an
Annotated[T, SkipSecretMasking()] marker that _mask_model checks before
recursing. The marker lives in openhands.sdk.utils to avoid the cycle
between secret_registry and llm.message, and both known base64 carriers
(BrowserObservation.screenshot_data and ImageContent.image_urls) are
tagged, which also transitively covers MCPToolObservation.from_call_tool_result
since it emits its data-URL through ImageContent. file_editor and
vision_inspect also produce their images through ImageContent, so the
opt-out reaches every current base64 sink without per-tool duplication.
The regression tests exercise both the generic marker (str and list[str]
shapes) and the end-to-end BrowserObservation → to_llm_content →
ImageContent path from the issue reproducer, and untagged sibling fields
are still asserted to be masked. Every current-head CI check is green.
Acceptance criteria
- Masking a
BrowserObservationleavesscreenshot_databyte-identical
when a registered secret's characters occur inside the base64
(test_secret_masker_leaves_screenshot_and_image_urls_alone). - A
data:image/*;base64,*URL insideImageContent.image_urlsis not
substring-replaced under the same condition (same test, plus
test_skip_secret_masking_covers_list_fields). - The MCP image path is covered transitively —
MCPToolObservation.from_call_tool_result
constructsImageContent(image_urls=[...]), and the tag on that field opts
the whole list out. No dedicated MCP test, but the mechanism reaches it. -
BrowserObservation.to_llm_contentyields anImageContentwhose data
URL still ends in the original payload after masking (asserted in the same
end-to-end test). - Text fields are still masked — the sibling
label/textfields in
both new tests assert the marker is still substituted where it should be. - No new required fields, serializer changes, or schema-version bump.
Annotatedmetadata is invisible to the wire format; previously persisted
events still load unchanged. -
Tool.__call__still routes every observation through
mask_secrets_in_model; new tools inherit masking by default and only
opt out per-field.
Observation (non-blocking)
Opting the entire image_urls list out of masking is the right call for the
base64 case, and the file comment says as much. It does mean that if a
caller ever puts a secret's characters into a plain remote URL (e.g., a
signed https://…?token=SECRET link), that string will no longer be masked
in that field. In practice masking such a URL would corrupt it anyway, and
this is called out in the design note, so it's a reasonable trade — flagging
only so a future reader doesn't rediscover it as a surprise.
[RISK ASSESSMENT]
Risk: LOW. Behavior change is confined to two field annotations plus a
23-line marker module; the semantic change is subtractive (some fields are
no longer scanned) and every current caller path is covered by the new
tests. No compatibility or serialization surface is touched.
Verdict: APPROVE.
Architectural insight. The regression was possible because a global,
unconditional pass mutated every string reachable from an observation.
Making the opt-out declarative on the field (rather than a per-tool
post-processing step) keeps a single chokepoint — Tool.__call__ still
routes through mask_secrets_in_model for every tool — while letting each
model own the "this field is an opaque payload" contract in its own
declaration. Future tools that carry binaries pick the safe default (still
masked) but have a one-line opt-out available at the site where the field
is defined.
This review was generated by an AI agent (OpenHands) on behalf of @jpshackelford.
Improve this review? If feedback seems incorrect or irrelevant, update the
repository's.agents/skills/custom-codereview-guide.md(with the/codereview
trigger), then re-request review. The reviewer reads the guide from the PR head.Resolve with AI? Install the
iterate skill
and run/iterate.Was this review helpful? React with 👍 or 👎.
|
Closing in favor of #5227. |
HUMAN:
Fixes issue #5224 — the secret masker corrupts base64 screenshot payloads and borks the conversation.
AGENT:
Why
Fixes #5224.
SecretRegistry.mask_secrets_in_modelwalked every string field on every observation and ran a plain substring.replace(secret_value, "<secret-hidden>")against it. When a field held a large opaque payload —BrowserObservation.screenshot_data, or adata:...;base64,...URL insideImageContent.image_urls— any registered secret whose raw characters happened to appear as a substring of the base64 (a near-certainty for any 8+ char token in a 200 KB+ screenshot) got the literal string<secret-hidden>spliced into the middle of the payload.The corrupted observation was persisted into the event store, so from that point on the LLM request built from history was rejected by the provider on every attempt (Anthropic
image.source.base64: invalid base64 data), permanently wedging the conversation.Regression was introduced by #4788, which wired
mask_secrets_in_modelinto the shared tool chokepoint. Present in every release from v1.45.0 through currentmain.Summary
SkipSecretMaskinginopenhands.sdk.utils.masking(re-exported fromopenhands.sdk.utils). Tag a Pydantic field withAnnotated[T, SkipSecretMasking()]and_mask_modelskips it entirely; ordinary fields are still walked and masked as before. The class docstring is the design note explaining when and why to reach for the marker.BrowserObservation.screenshot_data(raw base64 blob) andImageContent.image_urls(thedata:...;base64,...URLs rendered from it) so both round-trip byte-for-byte through the masker. Remote URLs never legitimately embed a registered secret either, so opting the whole list out is safe and keeps the rule simple.openhands.sdk.utilsso both the masker (sdk.conversation.secret_registry) and the models it walks (sdk.llm.message, which the conversation package imports transitively) can reference it without an import cycle.Issue Number
Fixes #5224.
How to Test
Repro from the issue, run against this branch:
Before this change the assert fails with
iVBORw0KGgoAAA<secret-hidden>SUhEUgAAB4A==. On this branch it printsOK.Regression tests added:
tests/sdk/conversation/test_secret_registry_model_masking.py::test_skip_secret_masking_leaves_annotated_string_field_alone— generic marker coverage on a synthetic model.tests/sdk/conversation/test_secret_registry_model_masking.py::test_skip_secret_masking_covers_list_fields— same forlist[str]fields (matches theImageContent.image_urlsshape).tests/tools/browser_use/test_browser_observation.py::test_secret_masker_leaves_screenshot_and_image_urls_alone— end-to-end scenario from the issue: register a secret whose characters collide with base64, run a realBrowserObservation(plus theImageContentit renders) through the masker, and assert the payload is byte-identical while the surrounding prose is still masked.Full local run (fix branch):
Video/Screenshots
N/A — pure logic change in the secret masker plus field-level tags. Behavior is captured by the assertions in the tests above.
Type
Notes
Companion issue #5225 tracks the recovery-path gap: even with this fix, a single provider-rejected
tool_resultstill wedges the whole conversation becauseLLMBadRequestErrorhas no recovery path inAgent.step. Out of scope for this PR.This pull request was created by an AI agent (OpenHands) on behalf of @jpshackelford.