Skip to content

fix(ai): strip trailing newlines and whitespace from provider API keys (#1437) - #1438

Open
Shubh2-0 wants to merge 1 commit into
conductor-oss:mainfrom
Shubh2-0:fix/trim-provider-api-keys-1437
Open

fix(ai): strip trailing newlines and whitespace from provider API keys (#1437)#1438
Shubh2-0 wants to merge 1 commit into
conductor-oss:mainfrom
Shubh2-0:fix/trim-provider-api-keys-1437

Conversation

@Shubh2-0

Copy link
Copy Markdown

Fixes #1437

Description

When provider API keys or env vars are loaded from secrets, .env files or command line expansions (e.g. cat keyfile), they often contain trailing newlines (\n) or surrounding whitespace. When passed into HTTP client Authorization headers, Java HTTP clients reject the raw 0x0a newline byte and throw 'Unexpected char 0x0a in Authorization value'.

Changes Made

  1. At Ingestion: Updated \EnvVarLookup.lookup()\ and \EnvVarLookup.allWithPrefix()\ to sanitize retrieved values via .strip(), ensuring trailing newlines and whitespace are stripped at resolution time.
  2. At API Client Constructors: Added defensive .strip()\ sanitization across provider HTTP API clients (\OpenAIChatCompletionsApi, \OpenAIEmbeddingsApi, \AnthropicMessagesApi) when building authorization headers.
  3. Unit Tests: Added \EnvVarLookupTest\ and updated \OpenAITest\ to verify trailing newline stripping.

Verification

  • Tested with \EnvVarLookupTest\ (verifying \n stripping on secret resolution).
  • Ran provider test suites via ./gradlew :conductor-ai:test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provider API keys aren't trimmed/validated — trailing newline → cryptic "Unexpected char 0x0a in Authorization value"

1 participant