Repository navigation
Description
Problem
The Agent Server must reject empty credentials during dormant initialization and keep secrets out of completion logs. These four small PRs cover the related paths.
Scope
- Reject empty session API keys before
/api/initchanges server state: fix(agent-server): ignore empty session API keys #5659. - Treat a blank
OH_SECRET_KEYas missing and fail closed if no usable key remains: fix(agent-server): treat an empty OH_SECRET_KEY as unset #5660. - Mask credential options and recognizable provider-error secrets in completion logs: fix(llm): keep provider credentials out of completion logs #5657.
- Keep
/sockets/*and/v1routes gated while the server is dormant: fix(agent-server): keep sockets and /v1 closed until deferred init completes #5661.
Done when
Each PR has focused tests for its path, all required checks pass, and a security reviewer has reviewed the combined behavior. If one initialization PR merges first, rebase the other to avoid keeping the same guard twice.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Umbrella hardening issue for four security fixes in the dormant Agent Server lifecycle, all surfaced by the Agent Server feature map (#5621). The four concrete changes already exist as open PRs, so the smallest coherent scope is exactly those paths; there is no open product or design decision to resolve. Scope (one path per PR): reject empty session API keys before /api/init mutates server state (#5659, Config.session_api_keys normalization plus both WebSocket auth paths and default-bind selection); treat a blank OH_SECRET_KEY as missing and fail closed (#5660, Config.secret_key validator plus /api/init _build_initialized_config); mask credential options and recognizable provider-error secrets in completion logs (#5657, Telemetry.on_request/on_error via sanitize_dict); keep /sockets/* and /v1 gated while dormant (#5661, require_initialized extended to HTTPConnection and the OpenAI router). Non-goals: no new public Python or REST/WebSocket API, no deprecation runway, and no behavior change for non-empty credentials; not changing deferred-init semantics or introducing a second auth/redaction mechanism; the empty require_initialized guard in #5661 was reviewed and intentionally left as-is; deciding which PR merges first and rebasing the other is coordination, not a product decision. readiness_check is absent and the issue's own "Done when" already states the intent, so no additional readiness sections are required.
Acceptance Criteria
Credential handling during initialization
-
Config.session_api_keysdrops empty strings from every input path (environment slots, JSON config file, and directConfig(...)):[""]becomes[]and[key, ""]becomes[key], so a blankOH_SESSION_API_KEYS_0no longer counts as auth configured when the default bind address is chosen. - Both WebSocket auth paths (legacy query/header and first-frame auth) refuse an empty presented key while non-empty keys authenticate exactly as before, so an empty string is never accepted as a credential.
-
Config.secret_keytreats a blank value (""or whitespace-only) as unset for env, JSON config file, and directConfig(...), falling back to_default_secret_key(); a non-emptysecret_keybehaves exactly as before. - When no usable key remains,
Config.cipherisNoneand the "OH_SECRET_KEY was not defined" warning is logged, so sensitive data is redacted rather than encrypted under an empty key. -
/api/init_build_initialized_configalso ignores an emptysecret_key, sincemodel_copyskips validators: a body withsession_api_keysbut no/blanksecret_keysetssecret_keyto the first session key, and a body with neither leaves the server without a cipher and logs the warning. - No guard is duplicated when both initialization PRs land (one merged first, the other rebased), and no other code path can construct
Cipher("")from a blank configured key.
Dormant gating for /sockets/* and /v1
- Before
POST /api/initon adeferred_init=Trueserver,/api/**keeps returning the dormant 503,/sockets/*WebSocket handshakes are refused withWebSocketExceptioncode 1013 (Try Again Later) before the socket is accepted, and/v1OpenAI-compatible routes return 503 for bothX-Session-API-KeyandAuthorization: Bearerclients. - After a successful
POST /api/init,/sockets/*and/v1are reachable again using the delivered session keys. - When
init_serviceisNone(non-deferred deployments) the gate is a no-op, so existing non-deferred behavior is unchanged.
Completion-log masking
- With completion logging enabled, provider credential headers (including an
Authorizationadded in place by a provider handler during the live call) do not appear in the logged call kwargs, in locallog_completions_folderfiles, or in agent-serverLLMCompletionLogEventrecords; credential-like values log as<redacted>while non-credential headers keep their values. - The masking covers both the success path (
log_llm_call) and the failure path (on_error), so a failed completion cannot leak credentials either.
Tests and validation
- Each of the four paths has an automated test that fails on the base revision: empty session key rejected for HTTP and WebSocket, blank
secret_keytreated as unset, credential header absent from a completion log on both success and failure, and dormant/sockets/*+/v1gated then unblocked after/api/init. - Required repository checks pass, including the relevant
tests/agent_serversuites and pre-commit gates (ruff, pyright,check-import-rules,check-tool-registration). - A security reviewer has reviewed the combined behavior of the four changes, including the affected agent-server REST/WebSocket contract surface.
Activity