mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:34:31 +00:00
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:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user