mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(gateway): block cached device token override fallback
This commit is contained in:
@@ -402,6 +402,26 @@ describe("GatewayClient connect auth payload", () => {
|
||||
client.stop();
|
||||
});
|
||||
|
||||
it("uses explicit shared password and does not inject stored device token", () => {
|
||||
loadDeviceAuthTokenMock.mockReturnValue({ token: "stored-device-token" });
|
||||
const client = new GatewayClient({
|
||||
url: "ws://127.0.0.1:18789",
|
||||
password: "shared-password", // pragma: allowlist secret
|
||||
});
|
||||
|
||||
client.start();
|
||||
const ws = getLatestWs();
|
||||
ws.emitOpen();
|
||||
emitConnectChallenge(ws);
|
||||
|
||||
expect(connectFrameFrom(ws)).toMatchObject({
|
||||
password: "shared-password", // pragma: allowlist secret
|
||||
});
|
||||
expect(connectFrameFrom(ws).token).toBeUndefined();
|
||||
expect(connectFrameFrom(ws).deviceToken).toBeUndefined();
|
||||
client.stop();
|
||||
});
|
||||
|
||||
it("uses stored device token when shared token is not provided", () => {
|
||||
loadDeviceAuthTokenMock.mockReturnValue({ token: "stored-device-token" });
|
||||
const client = new GatewayClient({
|
||||
|
||||
@@ -254,9 +254,12 @@ export class GatewayClient {
|
||||
? loadDeviceAuthToken({ deviceId: this.opts.deviceIdentity.deviceId, role })?.token
|
||||
: null;
|
||||
// Keep shared gateway credentials explicit. Persisted per-device tokens only
|
||||
// participate when no explicit shared token is provided.
|
||||
// participate when no explicit shared token/password is provided.
|
||||
const resolvedDeviceToken =
|
||||
explicitDeviceToken ?? (!explicitGatewayToken ? (storedToken ?? undefined) : undefined);
|
||||
explicitDeviceToken ??
|
||||
(!(explicitGatewayToken || this.opts.password?.trim())
|
||||
? (storedToken ?? undefined)
|
||||
: undefined);
|
||||
// Legacy compatibility: keep `auth.token` populated for device-token auth when
|
||||
// no explicit shared token is present.
|
||||
const authToken = explicitGatewayToken ?? resolvedDeviceToken;
|
||||
|
||||
Reference in New Issue
Block a user