Security: SecretRegistry leaks rotated credentials in cleartext after update_secrets() or LookupSecret re-export (and drops masked history across sub-agents)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
Direzione di ricerca
Start with openhands-sdk/openhands/sdk/conversation/secret_registry.py, especially update_secrets, value resolution, and masking; then read openhands-tools/openhands/tools/task/manager.py and openhands-tools/openhands/tools/delegate/impl.py for sub-agent propagation. Run the existing tests under tests/sdk/conversation/, tests/tools/task/, and tests/tools/delegate/; done means rotated values remain masked and sub-agents inherit and sync masking values. A linked pull request (#7003) is already open.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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: continueBecause
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
PY
Running 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.
- Lingua principale
- Python
- Stelle
- 1.4k
- Fork
- 797
- Merge medio
- 1g 17h
- PR unite (30g)
- 354
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OpenHands/software-agent-sdk
-
[Bug]: `list_directory` reports a complete listing as truncated when a directory has exactly 500 entriesForse già presa @balabommablock-cpu l’ha presa 29 giorni fa. Apertabug priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
OpenHands/software-agent-sdk#6133 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Command hook that exits 1 is treated as blocking when its stdout is a JSON `deny` or `continue: false`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OpenHands/software-agent-sdk#6116 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: TypeScript GET-with-body requests remain pending after a truncated responseForse già presa @BlueRaddish l’ha presa 34 giorni fa. Apertabug priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
OpenHands/software-agent-sdk#6059 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Document whether `prompt_tokens` includes `cache_read_tokens` in accumulated token usageForse già presa @Jaxon1216 l’ha presa 36 giorni fa. Apertapriority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
OpenHands/software-agent-sdk#5975 ·
I maintainer di solito rispondono entro 1 giorno
-
priority:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
OpenHands/software-agent-sdk#5708 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di OpenHands/software-agent-sdk
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
trycua/hermes-cua-spaces#17 ·
-
area:codegen backend:hip bug direction:output good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
status:waiting-for-triage type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
microsoftgraph/msgraph-sdk-python#1628 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
nautechsystems/nautilus_trader#5718 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: reme CLI crashes when the running server used a relative config pathForse già presa @nurlanmnn l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
agentscope-ai/ReMe#770 ·
I maintainer di solito rispondono entro 1 giorno