fix(auth): strip line breaks from pasted keys

This commit is contained in:
Peter Steinberger
2026-02-09 11:25:54 -06:00
parent fb8c653f53
commit 42a07791c4
15 changed files with 293 additions and 30 deletions

View File

@@ -4,6 +4,10 @@ import type { OpenClawConfig } from "../config/config.js";
import type { ModelProviderAuthMode, ModelProviderConfig } from "../config/types.js";
import { formatCliCommand } from "../cli/command-format.js";
import { getShellEnvAppliedKeys } from "../infra/shell-env.js";
import {
normalizeOptionalSecretInput,
normalizeSecretInput,
} from "../utils/normalize-secret-input.js";
import {
type AuthProfileStore,
ensureAuthProfileStore,
@@ -48,8 +52,7 @@ export function getCustomProviderApiKey(
provider: string,
): string | undefined {
const entry = resolveProviderConfig(cfg, provider);
const key = entry?.apiKey?.trim();
return key || undefined;
return normalizeOptionalSecretInput(entry?.apiKey);
}
function resolveProviderAuthOverride(
@@ -236,7 +239,7 @@ export function resolveEnvApiKey(provider: string): EnvApiKeyResult | null {
const normalized = normalizeProviderId(provider);
const applied = new Set(getShellEnvAppliedKeys());
const pick = (envVar: string): EnvApiKeyResult | null => {
const value = process.env[envVar]?.trim();
const value = normalizeOptionalSecretInput(process.env[envVar]);
if (!value) {
return null;
}
@@ -387,7 +390,7 @@ export async function getApiKeyForModel(params: {
}
export function requireApiKey(auth: ResolvedProviderAuth, provider: string): string {
const key = auth.apiKey?.trim();
const key = normalizeSecretInput(auth.apiKey);
if (key) {
return key;
}