惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(gateway): expire browser tokens after auth rotation ·...
pgondhi987 · 2026-05-28 · via Recent Commits to openclaw:main

@@ -38,41 +38,89 @@ afterAll(() => {

3838

}

3939

});

404041-

async function openDeviceTokenWs(): Promise<WebSocket> {

41+

async function openDeviceTokenWsWithDetails(

42+

params: { issuerGeneration?: string; browserClient?: boolean } = {},

43+

): Promise<{

44+

ws: WebSocket;

45+

deviceId: string;

46+

hello: Awaited<ReturnType<typeof connectOk>> & {

47+

auth?: { deviceToken?: unknown };

48+

};

49+

}> {

4250

const identityPath = path.join(os.tmpdir(), `openclaw-shared-auth-${process.pid}-${port}.json`);

4351

const { loadOrCreateDeviceIdentity, publicKeyRawBase64UrlFromPem } =

4452

await import("../infra/device-identity.js");

45-

const { approveDevicePairing, requestDevicePairing, rotateDeviceToken } =

53+

const { approveDevicePairing, ensureDeviceToken, requestDevicePairing, rotateDeviceToken } =

4654

await import("../infra/device-pairing.js");

55+

const client = params.browserClient

56+

? {

57+

id: "openclaw-control-ui",

58+

version: "1.0.0",

59+

platform: "test",

60+

mode: "webchat",

61+

}

62+

: {

63+

id: "test",

64+

version: "1.0.0",

65+

platform: "test",

66+

mode: "test",

67+

};

47684869

const identity = loadOrCreateDeviceIdentity(identityPath);

4970

const pending = await requestDevicePairing({

5071

deviceId: identity.deviceId,

5172

publicKey: publicKeyRawBase64UrlFromPem(identity.publicKeyPem),

52-

clientId: "test",

53-

clientMode: "test",

73+

clientId: client.id,

74+

clientMode: client.mode,

5475

role: "operator",

5576

scopes: ["operator.admin"],

5677

});

5778

await approveDevicePairing(pending.request.requestId, {

5879

callerScopes: ["operator.admin"],

5980

});

60-

const rotated = await rotateDeviceToken({

61-

deviceId: identity.deviceId,

62-

role: "operator",

63-

scopes: ["operator.admin"],

64-

});

65-

expect(rotated.ok).toBe(true);

81+

let issuedDeviceToken = "";

82+

if (params.issuerGeneration) {

83+

const deviceToken = await ensureDeviceToken({

84+

deviceId: identity.deviceId,

85+

role: "operator",

86+

scopes: ["operator.admin"],

87+

issuer: {

88+

kind: "shared-gateway-auth",

89+

generation: params.issuerGeneration,

90+

},

91+

});

92+

expect(deviceToken?.token).toBeTypeOf("string");

93+

issuedDeviceToken = deviceToken?.token ?? "";

94+

} else {

95+

const rotated = await rotateDeviceToken({

96+

deviceId: identity.deviceId,

97+

role: "operator",

98+

scopes: ["operator.admin"],

99+

});

100+

expect(rotated.ok).toBe(true);

101+

issuedDeviceToken = rotated.ok ? rotated.entry.token : "";

102+

}

6610367-

const ws = new WebSocket(`ws://127.0.0.1:${port}`);

104+

const ws = new WebSocket(

105+

`ws://127.0.0.1:${port}`,

106+

params.browserClient ? { headers: { origin: `http://127.0.0.1:${port}` } } : undefined,

107+

);

68108

trackConnectChallengeNonce(ws);

69109

await new Promise<void>((resolve) => ws.once("open", resolve));

70-

await connectOk(ws, {

110+

const hello = (await connectOk(ws, {

71111

skipDefaultAuth: true,

112+

client,

72113

deviceIdentityPath: identityPath,

73-

deviceToken: rotated.ok ? rotated.entry.token : "",

114+

deviceToken: issuedDeviceToken,

74115

scopes: ["operator.admin"],

75-

});

116+

})) as Awaited<ReturnType<typeof connectOk>> & {

117+

auth?: { deviceToken?: unknown };

118+

};

119+

return { ws, deviceId: identity.deviceId, hello };

120+

}

121+122+

async function openDeviceTokenWs(params: { issuerGeneration?: string } = {}): Promise<WebSocket> {

123+

const { ws } = await openDeviceTokenWsWithDetails(params);

76124

return ws;

77125

}

78126

@@ -165,6 +213,128 @@ describe("gateway shared auth rotation", () => {

165213

await closeWsAndWait(ws);

166214

}

167215

});

216+217+

it("disconnects issuer-tagged device-token websocket sessions after shared token rotation", async () => {

218+

const { resolveSharedGatewaySessionGeneration } =

219+

await import("./server/ws-shared-generation.js");

220+

const issuerGeneration = resolveSharedGatewaySessionGeneration({

221+

mode: "token",

222+

token: OLD_TOKEN,

223+

allowTailscale: false,

224+

});

225+

expect(issuerGeneration).toBeTypeOf("string");

226+

if (!issuerGeneration) {

227+

throw new Error("expected shared gateway generation");

228+

}

229+

const ws = await openDeviceTokenWs({

230+

issuerGeneration,

231+

});

232+

try {

233+

const closed = waitForGatewayWsClose(ws);

234+

const res = await sendSharedTokenRotationPatch(ws);

235+236+

expect(res.ok).toBe(true);

237+

await expect(closed).resolves.toEqual({

238+

code: 4001,

239+

reason: "gateway auth changed",

240+

});

241+

} finally {

242+

await closeWsAndWait(ws);

243+

}

244+

});

245+246+

it("preserves issuer-tagged browser device tokens on reconnect", async () => {

247+

const { getPairedDevice, verifyDeviceToken } = await import("../infra/device-pairing.js");

248+

const { resolveSharedGatewaySessionGeneration } =

249+

await import("./server/ws-shared-generation.js");

250+

const issuerGeneration = resolveSharedGatewaySessionGeneration({

251+

mode: "token",

252+

token: OLD_TOKEN,

253+

allowTailscale: false,

254+

});

255+

expect(issuerGeneration).toBeTypeOf("string");

256+

if (!issuerGeneration) {

257+

throw new Error("expected shared gateway generation");

258+

}

259+

const { ws, deviceId, hello } = await openDeviceTokenWsWithDetails({

260+

issuerGeneration,

261+

browserClient: true,

262+

});

263+

try {

264+

const helloDeviceToken = hello.auth?.deviceToken;

265+

if (typeof helloDeviceToken !== "string") {

266+

throw new Error("expected hello device token");

267+

}

268+

const paired = await getPairedDevice(deviceId);

269+

expect(paired?.tokens?.operator?.issuer).toEqual({

270+

kind: "shared-gateway-auth",

271+

generation: issuerGeneration,

272+

});

273+

await expect(

274+

verifyDeviceToken({

275+

deviceId,

276+

token: helloDeviceToken,

277+

role: "operator",

278+

scopes: ["operator.admin"],

279+

requiredSharedGatewaySessionGeneration: issuerGeneration,

280+

}),

281+

).resolves.toEqual({

282+

ok: true,

283+

issuer: {

284+

kind: "shared-gateway-auth",

285+

generation: issuerGeneration,

286+

},

287+

});

288+

} finally {

289+

await closeWsAndWait(ws);

290+

}

291+

});

292+293+

it("keeps issuer metadata when tagged device tokens reconnect through non-browser clients", async () => {

294+

const { getPairedDevice, verifyDeviceToken } = await import("../infra/device-pairing.js");

295+

const { resolveSharedGatewaySessionGeneration } =

296+

await import("./server/ws-shared-generation.js");

297+

const issuerGeneration = resolveSharedGatewaySessionGeneration({

298+

mode: "token",

299+

token: OLD_TOKEN,

300+

allowTailscale: false,

301+

});

302+

expect(issuerGeneration).toBeTypeOf("string");

303+

if (!issuerGeneration) {

304+

throw new Error("expected shared gateway generation");

305+

}

306+

const { ws, deviceId, hello } = await openDeviceTokenWsWithDetails({

307+

issuerGeneration,

308+

});

309+

try {

310+

const helloDeviceToken = hello.auth?.deviceToken;

311+

if (typeof helloDeviceToken !== "string") {

312+

throw new Error("expected hello device token");

313+

}

314+

const paired = await getPairedDevice(deviceId);

315+

expect(paired?.tokens?.operator?.issuer).toEqual({

316+

kind: "shared-gateway-auth",

317+

generation: issuerGeneration,

318+

});

319+

await expect(

320+

verifyDeviceToken({

321+

deviceId,

322+

token: helloDeviceToken,

323+

role: "operator",

324+

scopes: ["operator.admin"],

325+

requiredSharedGatewaySessionGeneration: issuerGeneration,

326+

}),

327+

).resolves.toEqual({

328+

ok: true,

329+

issuer: {

330+

kind: "shared-gateway-auth",

331+

generation: issuerGeneration,

332+

},

333+

});

334+

} finally {

335+

await closeWsAndWait(ws);

336+

}

337+

});

168338

});

169339170340

describe("gateway shared auth rotation with unchanged SecretRefs", () => {