Repository navigation
fix: redact API key from validate_profile error responses and logs - #4506
Merged
Merged
Conversation
The validate_profile endpoint (POST /api/profiles/{name}/validate) returned
exc.message directly in both the HTTP response body and the log line. When
LLM providers include the submitted API key in error messages (e.g. OpenAI's
'Incorrect API key provided: sk-proj-...'), the key was leaked to the client
and into server logs.
Apply redact_text_secrets() to all error messages before returning or logging
them, covering both the LLMError branch and the generic Exception branch.
Regression test verifies the key does not appear in the response for both
LLMAuthenticationError and generic RuntimeError paths.
Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
Contributor
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Contributor
Collaborator
Author
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
neubig
pushed a commit
that referenced
this pull request
Aug 17, 2026
…4506) Co-authored-by: openhands <openhands@all-hands.dev>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Given that this is reusing existing functionality in an appropriate place I think it makes sense.
AGENT:
Why
Source PR reviewed: #4422 — "feat: add pre-flight LLM validation endpoint (POST /api/profiles/{name}/validate)" (commit
46ad3d43).Risk lens: #8 (Credentials, redaction, and sensitive persistence boundaries) and #10 (Negative-space and silent-success cases).
Deterministic reproduction and impact:
The
validate_profileendpoint catchesLLMErrorand genericExceptionand returnsexc.message/str(exc)directly in the HTTP JSON response body (error.message) and in the server log line. When an LLM provider includes the submitted API key in its error message — as OpenAI does with"Incorrect API key provided: sk-proj-abc123..."— the key is leaked to the API client and persisted in server logs.Reproduction probe (run against unmodified
main):Captured log output on
main:Root cause: The endpoint did not apply any redaction to error messages before returning them to the client or logging them. The SDK already ships
redact_text_secrets()inopenhands.sdk.utils.redact, but it was not called.Summary
redact_text_secrets()toexc.messagein theLLMErrorcatch branch before returning it in the response or logging it.redact_text_secrets()tostr(exc)in the genericExceptioncatch branch for the same reason.LLMAuthenticationErrorpath and one for the genericRuntimeErrorpath, both asserting the API key does not appear in the response.Issue Number
N/A — found during weekly regression hunt.
How to Test
Proof that the regression test fails on unmodified
main:After fix:
End-to-end validation: The regression test constructs a real
TestClientagainst the FastAPI app, patchesLLM.acompletionto raise anLLMAuthenticationErrorwhose message contains a realistic OpenAI-style API key (sk-proj-abc123...), and asserts the key is absent from the JSON response body. A second test covers the genericExceptionpath with aRuntimeErrorcontaining the same key.Why the original tests did not catch the case: The existing tests for
validate_profilemockLLM.acompletionto raise errors with messages like"Connection refused"that do not contain secrets, so they pass regardless of whether redaction is applied. No test exercised the case where the provider error message contains the submitted API key — which is exactly the real-world scenario (OpenAI returns the key in auth error messages).Video/Screenshots
N/A — text-based reproduction; output included above.
Design Doc
N/A — minimal fix.
Type
Notes
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:648221b-pythonRun
All tags pushed for this build
About Multi-Architecture Support
648221b-python) is a multi-arch manifest supporting both amd64 and arm64648221b-python-amd64) are also available if needed