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

推荐订阅源

IT之家
IT之家
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The GitHub Blog
The GitHub Blog
MyScale Blog
MyScale Blog
爱范儿
爱范儿
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
Y
Y Combinator Blog
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
M
MIT News - Artificial intelligence
博客园 - Franky
V
Visual Studio Blog
I
InfoQ
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
博客园 - 司徒正美
L
LangChain Blog

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(openai): validate codex oauth token lifetimes · openc...
steipete · 2026-05-29 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -14,6 +14,20 @@ function timeoutError(): Error {

1414

return new DOMException("timed out", "TimeoutError");

1515

}

1616
17+

function mockTokenResponse(body: unknown, status = 200): void {

18+

mockTokenResponseText(JSON.stringify(body), status);

19+

}

20+
21+

function mockTokenResponseText(body: string, status = 200): void {

22+

ssrfMocks.fetchWithSsrFGuard.mockResolvedValueOnce({

23+

response: new Response(body, {

24+

status,

25+

headers: { "Content-Type": "application/json" },

26+

}),

27+

release: vi.fn(async () => undefined),

28+

});

29+

}

30+
1731

afterEach(() => {

1832

ssrfMocks.fetchWithSsrFGuard.mockReset();

1933

});

@@ -110,6 +124,24 @@ describe("OpenAI Codex OAuth flow", () => {

110124

});

111125

});

112126
127+

it("rejects unsafe token exchange lifetimes", async () => {

128+

mockTokenResponseText(

129+

'{"access_token":"access-token","refresh_token":"refresh-token","expires_in":1e309}',

130+

);

131+
132+

const result = await testing.exchangeAuthorizationCode(

133+

"code",

134+

"verifier",

135+

testing.resolveRedirectUri("localhost"),

136+

{ timeoutMs: 5 },

137+

);

138+
139+

expect(result).toEqual({

140+

type: "failed",

141+

message: "OpenAI Codex token exchange response missing fields: expires_in",

142+

});

143+

});

144+
113145

it("times out token refresh requests", async () => {

114146

ssrfMocks.fetchWithSsrFGuard.mockRejectedValueOnce(timeoutError());

115147

@@ -126,4 +158,19 @@ describe("OpenAI Codex OAuth flow", () => {

126158

message: "OpenAI Codex token refresh timed out after 5ms",

127159

});

128160

});

161+
162+

it("rejects non-positive token refresh lifetimes", async () => {

163+

mockTokenResponse({

164+

access_token: "access-token",

165+

refresh_token: "refresh-token",

166+

expires_in: 0,

167+

});

168+
169+

const result = await testing.refreshAccessToken("old-refresh-token", { timeoutMs: 5 });

170+
171+

expect(result).toEqual({

172+

type: "failed",

173+

message: "OpenAI Codex token refresh response missing fields: expires_in",

174+

});

175+

});

129176

});

Original file line numberDiff line numberDiff line change

@@ -5,6 +5,7 @@

55

* It is only intended for CLI use, not browser environments.

66

*/

77
8+

import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";

89

import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";

910

import { resolveCodexAuthIdentity } from "./openai-codex-auth-identity.js";

1011

import {

@@ -166,12 +167,17 @@ function formatMissingTokenResponseFields(json: TokenResponseJson): string {

166167

if (!json.refresh_token) {

167168

missing.push("refresh_token");

168169

}

169-

if (typeof json.expires_in !== "number") {

170+

if (parseStrictPositiveInteger(json.expires_in) === undefined) {

170171

missing.push("expires_in");

171172

}

172173

return missing.join(", ");

173174

}

174175
176+

function resolveTokenExpiresAt(expiresIn: unknown, nowMs = Date.now()): number | undefined {

177+

const seconds = parseStrictPositiveInteger(expiresIn);

178+

return seconds === undefined ? undefined : nowMs + seconds * 1000;

179+

}

180+
175181

function formatTokenRequestError(

176182

operation: "exchange" | "refresh",

177183

error: unknown,

@@ -253,7 +259,8 @@ async function exchangeAuthorizationCode(

253259
254260

const json = (await response.json()) as TokenResponseJson;

255261
256-

if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {

262+

const expires = resolveTokenExpiresAt(json.expires_in);

263+

if (!json.access_token || !json.refresh_token || expires === undefined) {

257264

return {

258265

type: "failed",

259266

message: `OpenAI Codex token exchange response missing fields: ${formatMissingTokenResponseFields(json)}`,

@@ -264,7 +271,7 @@ async function exchangeAuthorizationCode(

264271

type: "success",

265272

access: json.access_token,

266273

refresh: json.refresh_token,

267-

expires: Date.now() + json.expires_in * 1000,

274+

expires,

268275

};

269276

}

270277

@@ -294,7 +301,8 @@ async function refreshAccessToken(

294301
295302

const json = (await response.json()) as TokenResponseJson;

296303
297-

if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {

304+

const expires = resolveTokenExpiresAt(json.expires_in);

305+

if (!json.access_token || !json.refresh_token || expires === undefined) {

298306

return {

299307

type: "failed",

300308

message: `OpenAI Codex token refresh response missing fields: ${formatMissingTokenResponseFields(json)}`,

@@ -305,7 +313,7 @@ async function refreshAccessToken(

305313

type: "success",

306314

access: json.access_token,

307315

refresh: json.refresh_token,

308-

expires: Date.now() + json.expires_in * 1000,

316+

expires,

309317

};

310318

} catch (error) {

311319

return {