Repository navigation
Description
In plain words
A hook cannot use the conversation's secrets. If a hook command references $MY_API_KEY (a secret registered on the conversation), the variable resolves to empty at hook runtime — even though the same secret works fine when the agent runs it via execute_command. The hook should have access to the secret of the conversation it runs in.
What I verified (openhands-sdk 1.58.2, matching main)
The hook subprocess environment is built in HookExecutor.execute() (openhands-sdk/openhands/sdk/hooks/executor.py, ~L481):
hook_env = sanitized_env()
hook_env["OPENHANDS_PROJECT_DIR"] = self.working_dir
hook_env["OPENHANDS_SESSION_ID"] = event.session_id or ""
hook_env["OPENHANDS_EVENT_TYPE"] = event.event_type
if event.tool_name:
hook_env["OPENHANDS_TOOL_NAME"] = event.tool_namesanitized_env()deliberately strips the ambient environment, so nothing secret-bearing leaks in — but the conversation'sSecretRegistryis never consulted. There are zero references to secrets anywhere inopenhands/sdk/hooks/(grep forsecretcomes up empty).HookManager(openhands-sdk/openhands/sdk/hooks/manager.py) also has no secret-registry reference, and neithercreate_hook_callback()norHookEventProcessorthread one through.- Agent hooks spawn a
LocalConversationsub-conversation in_execute_agent_hook()without forwarding secrets either, so a hook sub-agent running bash can't see them either. - The irony:
SecretRegistry.get_all_secrets_as_env_vars()(openhands-sdk/openhands/sdk/conversation/secret_registry.py) already exists and its docstring says it is meant "for opaque consumers (e.g. an ACP CLI subprocess) that cannot be name-scanned per command and must receive their credentials upfront". Command hooks are exactly such a consumer — the hook command string is never name-scanned — but the hook path never calls it. By contrast, the agent's own bash commands do get secrets viaget_secrets_as_env_vars()name-scanning, which is why the agent works and hooks don't.
Steps to reproduce
-
Create a conversation and register a secret, e.g.
FOO=bar(via the conversation secrets API / secret store). -
Configure a hook, e.g. on
PreToolUse:{ "pre_tool_use": [{ "command": "echo \"FOO=${FOO:-UNSET}\"" }] } -
Trigger any tool call. The
HookExecutionEventstdout showsFOO=UNSET. -
Compare with the agent running
execute_commandecho $FOO→bar(masked as<secret-hidden>in output).
Expected
The hook should have access to the secret of the conversation. A hook doing curl -H "Authorization: Bearer $MY_TOKEN" ... should work.
Suggested approach
- Pass the conversation's
SecretRegistry(or a name→value resolver callable) intocreate_hook_callback()→HookManager→HookExecutor(the wiring already passesllm,llm_getter,visualizer, etc. the same way). - Inject the full registry via
get_all_secrets_as_env_vars()intohook_envfor command hooks (hooks are opaque consumers — their commands aren't name-scanned), and/or offer per-hook opt-out to keep least privilege. - Injection should go through
get_secret_value()/track_exported_values()so values land in_exported_valuesand hookstdout/stderrpersisted inHookExecutionEventstay masked. - Agent-hook sub-conversations should receive the parent conversation's secrets.
Notes
- Scope: command hooks (subprocess env) and agent hooks (sub-conversation secrets). Prompt hooks don't need it (they call the LLM directly), but injected
additionalContextflows are unaffected. - Security consideration: injecting the whole registry into every hook widens credential exposure to arbitrary hook commands; masking already covers persisted hook output, and an explicit per-hook allowlist (opt-in) could be the conservative default.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Verified on main: the hook subprocess environment in HookExecutor.execute() (openhands-sdk/openhands/sdk/hooks/executor.py) is built from sanitized_env() and never consults the conversation's SecretRegistry; there are zero references to secrets under openhands/sdk/hooks/. Both create_hook_callback() call sites in LocalConversation (initial plugin load and hook reconfiguration) thread llm_getter, visualizer, and conversation_stats but no secret resolver, and the agent-hook sub-conversation created in _execute_agent_hook() receives no secrets either. SecretRegistry.get_all_secrets_as_env_vars() already exists for opaque consumers and routes values through track_exported_values(), so the mechanism the issue points to is real and unused. The reporter's repro, code citations, and masking analysis check out; this is a genuine gap, not a usage question.
Bounded scope: command hooks receive the conversation's registered secrets in the hook subprocess environment, and agent hooks forward the parent conversation's secrets to their sub-conversation, using the existing SecretRegistry resolution and tracking machinery. Nothing in the issue or repository records a user report, support evidence, or production failure beyond the reporter's own verification, so this stays at priority:low.
Non-goals: per-hook secret allowlists or opt-in scoping (the get_all_secrets_as_env_vars() docstring defers least-privilege scoping to #1039 task 6); name-scanning hook command strings for selective injection; changing prompt hooks (they call the LLM directly and need no secrets); new REST/WebSocket API surface; changes to how the agent's own bash commands receive secrets; and any relaxation of existing secret masking in persisted events and logs.
Acceptance Criteria
- With a registered conversation secret
FOOand a command hook whose command prints the value of$FOO, a triggered tool call produces aHookExecutionEventwhosestdoutresolves the secret value instead of empty/unset, while the raw value is masked as<secret-hidden>in the persisted event. - Command hook subprocess environments continue to expose the existing non-secret context (
OPENHANDS_PROJECT_DIR,OPENHANDS_SESSION_ID,OPENHANDS_EVENT_TYPE,OPENHANDS_TOOL_NAME,PLUGIN_ROOT) with unchanged semantics. - An agent hook whose sub-agent runs a bash command referencing a registered secret sees that secret resolve in the sub-conversation, with the parent conversation's secrets available.
- Hook command execution with zero registered secrets behaves identically to the pre-change behavior (same environment keys, same results).
- A secret whose lookup fails or resolves to an empty value is omitted from the hook environment without failing or blocking hook execution.
- Secret values injected for hooks are registered in the same exported-values tracking used by
SecretRegistry, so hookstdout/stderrpersisted inHookExecutionEventand in logs never contain plaintext secret values, matching the masking behavior of agent bash output. - All existing hook tests pass unchanged except where they asserted the absence of secrets, and a test covers that a command hook referencing a registered secret receives it, including its masked persisted output.
Activity
docs(verify): MCP start failures fixed; map #6993, #6992, #6966 (F19,…