fix: prevent undefined token in gateway auth config (#13809)

- Guard against undefined/empty token in buildGatewayAuthConfig
- Automatically generate random token when token param is undefined, empty, or whitespace
- Prevents JSON.stringify from writing literal string "undefined" to config
- Add tests for undefined, empty, and whitespace token cases

Fixes #13756

Co-authored-by: Klawd Asklee <klawdebot@gmail.com>
This commit is contained in:
asklee-klawd
2026-02-12 14:45:38 +01:00
committed by GitHub
parent 2ef4ac08cf
commit f8c91b3c5f
2 changed files with 43 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import {
promptModelAllowlist,
} from "./model-picker.js";
import { promptCustomApiConfig } from "./onboard-custom.js";
import { randomToken } from "./onboard-helpers.js";
type GatewayAuthChoice = "token" | "password";
@@ -35,7 +36,9 @@ export function buildGatewayAuthConfig(params: {
}
if (params.mode === "token") {
return { ...base, mode: "token", token: params.token };
// Guard against undefined/empty token to prevent JSON.stringify from writing the string "undefined"
const safeToken = params.token?.trim() || randomToken();
return { ...base, mode: "token", token: safeToken };
}
return { ...base, mode: "password", password: params.password };
}