Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
SecretRegistry (openhands-sdk/openhands/sdk/conversation/secret_registry.py) leaks credentials in cleartext into persisted events/*.json, LLM context, and WebSocket event streams whenever a secret is rotated mid-conversation — such as refreshing an OAuth / GitHub App installation token via POST /api/conversations/{id}/secrets (EventService.update_secrets -> LocalConversation.update_secrets), updating a key via conversation.update_secrets(...), or re-exporting a rotating LookupSecret / SecretSource.
Three compounding defects cause plaintext credential exposure:
-
update_secrets()leaves the newly updated active secret completely unmasked in cleartext:
SecretRegistry.update_secrets(secret_registry.py:196-208) overwritesself.secret_sources[name]without invalidatingself._exported_values[name]orself._failed_lookups[name].
Whenmask_secrets_in_output(secret_registry.py:309-337) runsresolve_uncached_values()(secret_registry.py:290-308):for key in list(self.secret_sources): if key in self._exported_values: continue
Because
nameis already inself._exported_valuesfrom its initial value (or inself._failed_lookupsif an earlier lookup failed withinFAILED_LOOKUP_RETRY_SECONDS),resolve_uncached_values()skipsnameand never resolves the new secret value. Any tool output (file_editor,grep,glob, MCP tools,git remote -v/cat .env,MessageEvent,SecurityAnalysisEvent) containing the currently active refreshed secret writes it in cleartext until a terminal command explicitly names$SECRET_NAME. -
Exporting a rotated secret (
update_secretsorLookupSecret) overwrites_exported_values[key], leaking the previous credential in cleartext:
self._exported_values(secret_registry.py:187, 191-194) is adict[str, str]storing only a single string per key:def track_exported_values(self, values: Mapping[str, str]) -> None: with self._exported_values_lock: self._exported_values.update({k: v for k, v in values.items() if v})
As soon as a terminal command references
$SECRET_NAME(callingget_secrets_as_env_varsorget_secret_value),self._exported_values[key]overwrites the previous secret value with the new one rather than retaining prior resolved values for masking. When the prior token still exists in.git/config, workspace logs, or build artifacts (or remains valid during overlap windows),mask_secrets_in_outputandcompile_stream_maskno longer mask it — directly violatingmask_secrets_in_output's own documented invariant (secret_registry.py:314-315: "so a rotated secret masks its previous value"). -
Sub-agent delegation drops historical masked values (and
DelegateExecutoromitssecretsaltogether):TaskManager._get_conversationandTaskManager._resume_task(openhands-tools/openhands/tools/task/manager.py:224, 324) passsecrets=parent.state.secret_registry.secret_sources, starting each sub-agent with a freshSecretRegistrythat lacks the parent's previously resolved/rotated secret values, and never merge values resolved inside the sub-agent (e.g., from a dynamic/one-timeLookupSecret) back into the parent's masking set.DelegateExecutor._spawn_agents(openhands-tools/openhands/tools/delegate/impl.py:227-248) does not passsecretstoLocalConversationat all, leaving delegated sub-agents with an emptySecretRegistrythat leaks 100% of parent secrets in cleartext.
Discovered during secret-confinement and credential-rotation auditing with TraceTrial-Bench (arXiv:2610.32285, mechanism nodes G4 — secret masking & representation confinement, C2 — credential rotation & redaction, and L — sub-agent delegation lifecycle).
Expected Behavior
- Calling
update_secrets({name: new_value})preserves any previously resolved value fornamein the registry's masking history, clears any stale_failed_lookups[name]backoff entry, and ensuresresolve_uncached_values()/mask_secrets_in_output()resolves and masksnew_valueimmediately — even before any terminal command names$SECRET_NAME. - Re-exporting or looking up a rotated secret (
update_secretsor a dynamicLookupSecret/SecretSource) keeps both historical resolved values and the latest value masked (<secret-hidden>) inmask_secrets_in_output,mask_secrets_in_model, andcompile_stream_mask. - Sub-agents spawned or resumed via
TaskManagerandDelegateExecutorinherit the parent'ssecret_sourcesand known masked values, and values resolved during sub-agent execution are synced back to the parent'sSecretRegistryfor masking.
Actual Behavior
On current main, both the newly updated active secret and previously exported rotated secrets leak in cleartext:
uv sync --frozen --dev
uv run python - <<'PY'
from openhands.sdk.conversation.secret_registry import SecretRegistry
from openhands.sdk.secret import SecretSource
class RotatingTokenSource(SecretSource):
calls: int = 0
def get_value(self) -> str:
self.calls += 1
return f"dyn_token_v{self.calls}_secret"
reg = SecretRegistry()
reg.update_secrets(
{"DEPLOY_TOKEN": "static_tok_v1_secret", "OAUTH_TOKEN": RotatingTokenSource()}
)
# Initial masking caches v1 of both secrets
assert "<secret-hidden>" in reg.mask_secrets_in_output(
"init static_tok_v1_secret dyn_token_v1_secret"
)
# 1. Mid-session token refresh via update_secrets() (e.g. POST /api/conversations/{id}/secrets)
reg.update_secrets({"DEPLOY_TOKEN": "static_tok_v2_secret"})
masked_new = reg.mask_secrets_in_output("config contains static_tok_v2_secret")
assert "static_tok_v2_secret" not in masked_new, (
f"Active refreshed secret leaked in cleartext: {masked_new!r}"
)
# 2. Next terminal command exports $DEPLOY_TOKEN and $OAUTH_TOKEN
reg.get_secrets_as_env_vars("deploy --token $DEPLOY_TOKEN --oauth $OAUTH_TOKEN")
masked_prev = reg.mask_secrets_in_output(
"git remote has static_tok_v1_secret and log has dyn_token_v1_secret"
)
assert "static_tok_v1_secret" not in masked_prev
assert "dyn_token_v1_secret" not in masked_prev
PYRunning the snippet above on main fails immediately with:
AssertionError: Active refreshed secret leaked in cleartext: 'config contains static_tok_v2_secret'
(and after get_secrets_as_env_vars, both static_tok_v1_secret and dyn_token_v1_secret also leak unmasked).
Acceptance Criteria
- After
SecretRegistry.update_secrets({name: new_source_or_value}),mask_secrets_in_outputandmask_secrets_in_modelmask both the newly updated value (without requiring a terminal command to referencenamefirst) and any previously resolved value(s) forname, and stale_failed_lookups[name]backoff state is cleared for updated keys. - When a
LookupSecretor customSecretSourcereturns a rotated value onget_secrets_as_env_vars/get_secret_value, previously resolved values remain masked alongside the newly exported value in bothmask_secrets_in_outputandcompile_stream_mask. -
TaskManager(on task creation and resumption) andDelegateExecutor._spawn_agentspropagate parentsecret_sourcesand known masked secret values to sub-agent conversations, and sync sub-agent-resolved masked values back into the parent'sSecretRegistry. - Unit and integration tests under
tests/sdk/conversation/,tests/tools/task/, andtests/tools/delegate/coverupdate_secretsrotation masking,LookupSecretrotation masking, failed-lookup recovery onupdate_secrets, and parent/sub-agent secret masking propagation without cleartext leaks in persisted events.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Verified against main in this repository: SecretRegistry.update_secrets() (openhands-sdk/openhands/sdk/conversation/secret_registry.py) overwrites secret_sources without invalidating _exported_values or _failed_lookups, so resolve_uncached_values() skips the updated key and the new value is never resolved for masking until a command names it; track_exported_values() stores a single string per key, so a re-export of a rotated LookupSecret/SecretSource replaces the previous value in the masking set and the prior credential leaks; and DelegateExecutor._spawn_agents (openhands-tools/openhands/tools/delegate/impl.py) builds sub-agent conv_kwargs without secrets, while TaskManager._get_conversation/_resume_task (openhands-tools/openhands/tools/task/manager.py) pass parent secret_sources only (no resolved masking values). The mask_secrets_in_output docstring already documents the invariant that a rotated secret masks its previous value, so the requested behavior is the documented contract, not a new design. The author reproduced the active-secret leak by running the real registry class on main.
Bounded scope: make SecretRegistry masking history rotation-safe, propagate parent secrets and resolved masking values to sub-agent conversations (both TaskManager and DelegateExecutor paths), and sync sub-agent-resolved values back for masking only.
Non-goals: no new redaction or secret-sentinel mechanism — masking must continue through SecretRegistry's existing masking per repository AGENTS.md ("Never introduce a parallel redaction or secret-sentinel implementation"); no change to terminal env-var injection or to get_all_secrets_as_env_vars scoping (least-privilege scoping remains deferred to #1039); no TypeScript client masking changes (#5708, #6377); no hook-environment secret injection (#6966); no change to persisted-settings or event schemas beyond masking behavior; child-registered secret sources remain child-local as pinned by tests/tools/task/test_secret_inheritance.py.
Acceptance Criteria
- After
SecretRegistry.update_secrets({name: new_value}),mask_secrets_in_outputandmask_secrets_in_modelmasknew_valueimmediately, without any prior export or terminal command referencingname, and also mask every previously resolved value forname. - After a secret lookup fails,
update_secretsfor that name allows immediate resolution and masking of the new value without waiting out the failed-lookup backoff window. - When a
LookupSecretor customSecretSourcereturns a rotated value on a laterget_secrets_as_env_vars/get_secret_value, both the previously exported value and the newly exported value are masked inmask_secrets_in_outputand incompile_stream_maskoutput. - Sub-agent conversations created by
TaskManager._get_conversationand_resume_taskstart with the parent's known resolved/masked secret values, and rotated or previously exported parent secrets appear masked (not cleartext) in sub-agent outputs. -
DelegateExecutor._spawn_agentspasses the parent's secret sources and known masked values to spawned sub-agent conversations, and parent secrets appear masked (not cleartext) in delegate sub-agent outputs. - A secret value resolved during sub-agent execution is masked in the parent conversation's subsequent outputs after the delegated task completes or resumes.
- Child-registered secret sources remain child-local: the behavior pinned by
tests/tools/task/test_secret_inheritance.py(child-only sources not registered on the parent) is preserved, with sub-agent value sync affecting masking only. - Regression tests under
tests/sdk/conversation/,tests/tools/task/, andtests/tools/delegate/cover update-secrets rotation masking,LookupSecretrotation masking, failed-lookup recovery on update, and parent/sub-agent propagation, and fail on currentmainbefore the fix. - Persisted
events/*.jsonfor parent and sub-agent conversations contain no cleartext occurrence of a rotated secret value in the covered scenarios.
Activity
all-hands-bot commentedon Nov 19, 2026
New report bundles three defects in SecretRegistry/secret delegation. Two are genuinely new (update_secrets() not invalidating _exported_values/_failed_lookups so the refreshed value is never resolved for masking; and _exported_values holding only one value per key so a re-export drops the previous value from masking). The third (sub-agent secret inheritance) is a stale re-report: #6724 covered the TaskManager paths and was closed as fixed by #6757, and the DelegateExecutor gap is the subject of open PR #7000. The rotation-masking contract question for the Python registry is already the explicit subject of #5708, whose triage decided Python's last-resolved-value behavior was intended and narrowed that issue to the TypeScript mirror. No single issue captures the update_secrets() masking bug, so nothing here should be auto-closed, but the author should be pointed at #5708 (rotation-masking policy decision) and #6724/#7000 (sub-agent secret propagation) before opening competing fixes.
Found 2 possible duplicate issues:
These may not be exact duplicates, but the scope appears to overlap enough that keeping discussion in one place may be more useful.
This comment was created by an AI assistant (OpenHands) on behalf of the repository maintainer.
enyst commentedon Nov 20, 2026
I'm an AI agent helping Engel Nyst (@enyst) with project work.
The daily feature-map pass reproduced this on main@722e5d40 on both surfaces:
Conversationwith a scripted terminal agent. Program:.agents/skills/verify-sdk/programs/S13/secret_rotation.py. The first run is masked. Afterupdate_secrets({"DEPLOY_TOKEN": "dep-v2-s13"}):new_value_leaksis["dep-v2-s13"].previous_values_leaksis["dep-v1-s13","oauth-v1-s13"].events/*.json.https://github.com/enyst/openhands-evidence/blob/3723e9c6bf25dd053c3b3ace90adc57885a1cb2f/software-agent-sdk/map-maintenance/2026-11-20/edited/sdk/final-S13/S13-security-confirmation-04.log).QA_ROT.OLD=<secret-hidden>.POST /api/conversations/{id}/secretswith a new value, printing the new value showsNEW=qa-rotnew-sekret.OLD2=qa-rotold-sekret.https://github.com/enyst/openhands-evidence/blob/3723e9c6bf25dd053c3b3ace90adc57885a1cb2f/software-agent-sdk/map-maintenance/2026-11-20/repro/7002-server/obs.json).The feature maps now mark it as a known failure (SDK
S13.secret-registry, agent-server Gotcha onF08.secrets-override) and point at #7003.Generated by Claude Code
zsicheng0214 commentedon Nov 21, 2026
Thanks @enyst for reproducing this across both surfaces and adding
S13/secret_rotation.py+F08.secrets-overridein #7031!We cherry-picked #7003 directly onto #7031 (
04abbc70) and ranS13/secret_rotation.pyend-to-end — all four leak checks (before_rotation_leaks,new_value_leaks,previous_values_leaks, andpersisted_leaks) drop to[](passed: true), alongside the sub-agent delegation masking sync tests (TaskManager+DelegateExecutor). Happy to rebase #7003 once #7031 lands if helpful!