Harden AI providers: no token leak in errors, request timeouts#342
Merged
Conversation
On non-200 responses both providers interpolated the response body into the returned error. A proxy that echoes the Authorization header in its error body would leak the API token into logs. Drop the body — return status code only, matching the Healthy methods. The token is only ever in the request header, so status-only removes the leak regardless of what the server echoes. Add defense-in-depth timeouts: defaultRequestTimeout + ensureTimeout apply a default deadline to non-streaming Query/Healthy when the caller's context has none. Not applied to StreamQuery or the shared http.Client.Timeout, either of which would truncate long token streams. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #342 +/- ##
==========================================
+ Coverage 66.38% 66.42% +0.04%
==========================================
Files 50 51 +1
Lines 8160 8170 +10
==========================================
+ Hits 5417 5427 +10
Misses 2368 2368
Partials 375 375 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
response body into the returned error. A proxy/gateway that echoes the
Authorization: Bearer <token>header in its error body would leak the tokeninto logs. Now return status code only (matching the
Healthymethods) —the token is only ever in the request header, so this removes the leak.
ensureTimeoutapplying a default 60s deadline tonon-streaming
Query/Healthywhen the caller's context has none.Not applied to
StreamQueryor the sharedhttp.Client.Timeout— eitherwould truncate long token streams.
Test plan
*_DoesNotLeakTokenInError— server echoes the Authorization header in a401 body; error contains
401but never the tokenTestOpenAIQuery_AppliesDefaultTimeout— hung server + deadline-lesscontext returns promptly
*_ServerErrortests (Contains("500")) still pass — status retainedmake test-allgreen (fmt, vet, lint, test, race, test-fixtures)No README trigger files touched.
🤖 Generated with Claude Code