Repository navigation
fix(sdk-kotlin): keep an explicit API key header ahead of the configured key - #2375
Merged
Pangjiping merged 1 commit intoOct 25, 2026
Conversation
…red key An explicit OPEN-SANDBOX-API-KEY supplied through ConnectionConfig headers should take precedence over the configured apiKey and its environment fallback, matching the JavaScript (opensandbox-group#2348) and C# header precedence contract. The authenticated client violated it: AuthenticationInterceptor runs after ExtraHeadersInterceptor and unconditionally replaces the API key header — OkHttp matches names case-insensitively — so the caller's explicitly supplied credential was always overwritten with the configured key. Skip the injection when the request already carries an API key header in any casing, mirroring the neighboring ClientIpInterceptor guard, and also skip it when no key is configured so authenticated requests no longer send an empty header value. Adds four MockWebServer regression tests: configured key carried, explicit canonical and lowercase headers preserved exactly once, and no header when unconfigured. Three fail on the base commit and pass after the fix; the full :sandbox and :code-interpreter suites (531 tests) and spotlessCheck pass.
xxwtiancai
requested review from
Pangjiping,
hittyt,
jwx0925 and
ninan-nn
as code owners
October 23, 2026 18:15
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Oct 25, 2026
9 of 10 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.
Summary
An explicit
OPEN-SANDBOX-API-KEYsupplied throughConnectionConfig.headersshould take precedence over the configuredapiKeyand its environment fallback — the same contract #2348 established for the JavaScript SDK and #2372 carries to C#. The Kotlin authenticated client violated it:HttpClientProvider'sAuthenticationInterceptorruns afterExtraHeadersInterceptor(which applies user-supplied headers) and unconditionally replaces the API key header — OkHttp matches header names case-insensitively — so a caller's explicitly supplied credential was always overwritten with the configured key, whatever casing was used.OPEN-SANDBOX-API-KEYheader value to every authenticated request, unlike the JS/C# SDKs which only attach the header when a key exists. (LifecycleMetricsReporteralready handled both aspects correctly.)The fix skips the injection when the request already carries an API key header in any casing (the same guard the neighboring
ClientIpInterceptoruses — its comment states the intent that a user-supplied value is preserved), and when the key is blank. Default injection is unchanged when the header is absent and a key is configured.Testing
ApiKeyHeaderTestuses MockWebServer end-to-end againstauthenticatedClient, following the existingClientIpTestpattern../gradlew spotlessCheck :sandbox:test :code-interpreter:test— 531 tests, 0 failures (JDK 8 toolchain provisioned locally for:code-interpreter).pnpm docs:buildwas not run (no pnpm available locally); the docs change is one prose paragraph indocs/sdks/kotlin.md.Breaking Changes
Checklist
docs/sdks/kotlin.md, mirroring the JavaScript/C# SDK notes)Prepared with AI assistance. Checked the open PR queue for in-flight Kotlin header-precedence work before submitting.