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

推荐订阅源

U
Unit 42
A
About on SuperTechFans
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
月光博客
月光博客
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
Jina AI
Jina AI
有赞技术团队
有赞技术团队
博客园_首页

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(minimax): reject unsafe oauth expiry · openclaw/openc...
steipete · 2026-05-30 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -13,4 +13,10 @@ describe("normalizeOAuthExpires", () => {

1313

it("preserves absolute millisecond timestamps", () => {

1414

expect(normalizeOAuthExpires(1_700_000_000_000)).toBe(1_700_000_000_000);

1515

});

16+
17+

it("rejects unsafe and malformed expiry values", () => {

18+

expect(normalizeOAuthExpires(Number.POSITIVE_INFINITY)).toBeUndefined();

19+

expect(normalizeOAuthExpires(Number.MAX_SAFE_INTEGER + 1)).toBeUndefined();

20+

expect(normalizeOAuthExpires("3600s")).toBeUndefined();

21+

});

1622

});

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,5 @@

11

import { randomBytes, randomUUID } from "node:crypto";

2+

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

23

import { generatePkceVerifierChallenge, toFormUrlEncoded } from "openclaw/plugin-sdk/provider-auth";

34

import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env";

45

@@ -57,14 +58,12 @@ type TokenResult =

5758

* Normalize MiniMax token endpoint `expired_in` values to the auth-profile

5859

* contract: absolute Unix milliseconds.

5960

*/

60-

export function normalizeOAuthExpires(expiredIn: number, now = Date.now()): number {

61-

if (expiredIn < MINIMAX_RELATIVE_EXPIRY_SECONDS_THRESHOLD) {

62-

return now + expiredIn * 1000;

63-

}

64-

if (expiredIn < MINIMAX_ABSOLUTE_EXPIRY_MS_THRESHOLD) {

65-

return expiredIn * 1000;

66-

}

67-

return expiredIn;

61+

export function normalizeOAuthExpires(expiredIn: unknown, now = Date.now()): number | undefined {

62+

return resolveExpiresAtMsFromDurationOrEpoch(expiredIn, {

63+

nowMs: now,

64+

relativeSecondsThreshold: MINIMAX_RELATIVE_EXPIRY_SECONDS_THRESHOLD,

65+

absoluteMillisecondsThreshold: MINIMAX_ABSOLUTE_EXPIRY_MS_THRESHOLD,

66+

});

6867

}

6968
7069

function generatePkce(): { verifier: string; challenge: string; state: string } {

@@ -165,7 +164,7 @@ async function pollOAuthToken(params: {

165164

status: string;

166165

access_token?: string | null;

167166

refresh_token?: string | null;

168-

expired_in?: number | null;

167+

expired_in?: unknown;

169168

token_type?: string;

170169

resource_url?: string;

171170

notification_message?: string;

@@ -182,13 +181,17 @@ async function pollOAuthToken(params: {

182181

if (!tokenPayload.access_token || !tokenPayload.refresh_token || !tokenPayload.expired_in) {

183182

return { status: "error", message: "MiniMax OAuth returned incomplete token payload." };

184183

}

184+

const expires = normalizeOAuthExpires(tokenPayload.expired_in);

185+

if (expires === undefined) {

186+

return { status: "error", message: "MiniMax OAuth returned invalid token expiry." };

187+

}

185188
186189

return {

187190

status: "success",

188191

token: {

189192

access: tokenPayload.access_token,

190193

refresh: tokenPayload.refresh_token,

191-

expires: normalizeOAuthExpires(tokenPayload.expired_in),

194+

expires,

192195

resourceUrl: tokenPayload.resource_url,

193196

notification_message: tokenPayload.notification_message,

194197

},

Original file line numberDiff line numberDiff line change

@@ -7,5 +7,6 @@ export {

77

positiveSecondsToSafeMilliseconds,

88

nonNegativeSecondsToSafeMilliseconds,

99

resolveExpiresAtMsFromDurationSeconds,

10+

resolveExpiresAtMsFromDurationOrEpoch,

1011

resolveExpiresAtMsFromEpochSeconds,

1112

} from "../shared/number-coercion.js";

Original file line numberDiff line numberDiff line change

@@ -13,6 +13,7 @@ export {

1313

positiveSecondsToSafeMilliseconds,

1414

nonNegativeSecondsToSafeMilliseconds,

1515

resolveExpiresAtMsFromDurationSeconds,

16+

resolveExpiresAtMsFromDurationOrEpoch,

1617

resolveExpiresAtMsFromEpochSeconds,

1718

} from "../shared/number-coercion.js";

1819

export { MAX_TCP_PORT, parseTcpPort } from "../infra/tcp-port.js";

Original file line numberDiff line numberDiff line change

@@ -8,6 +8,7 @@ import {

88

positiveSecondsToSafeMilliseconds,

99

resolveIntegerOption,

1010

resolveExpiresAtMsFromDurationSeconds,

11+

resolveExpiresAtMsFromDurationOrEpoch,

1112

resolveExpiresAtMsFromEpochSeconds,

1213

resolveNonNegativeIntegerOption,

1314

resolveOptionalIntegerOption,

@@ -100,6 +101,16 @@ describe("number-coercion", () => {

100101

expect(resolveExpiresAtMsFromEpochSeconds("1e309")).toBeUndefined();

101102

});

102103
104+

test("mixed expiry helper handles relative seconds, epoch seconds, and absolute milliseconds", () => {

105+

expect(resolveExpiresAtMsFromDurationOrEpoch(86_400, { nowMs: 1_700_000_000_000 })).toBe(

106+

1_700_086_400_000,

107+

);

108+

expect(resolveExpiresAtMsFromDurationOrEpoch(1_700_000_000)).toBe(1_700_000_000_000);

109+

expect(resolveExpiresAtMsFromDurationOrEpoch(1_700_000_000_000)).toBe(1_700_000_000_000);

110+

expect(resolveExpiresAtMsFromDurationOrEpoch(Number.POSITIVE_INFINITY)).toBeUndefined();

111+

expect(resolveExpiresAtMsFromDurationOrEpoch(Number.MAX_SAFE_INTEGER + 1)).toBeUndefined();

112+

});

113+
103114

test("integer option helpers floor finite values and fall back for non-finite values", () => {

104115

expect(resolveIntegerOption(7.9, 1, { min: 1, max: 10 })).toBe(7);

105116

expect(resolveIntegerOption(Number.NaN, 4.9, { min: 1 })).toBe(4);

Original file line numberDiff line numberDiff line change

@@ -180,3 +180,26 @@ export function resolveExpiresAtMsFromEpochSeconds(

180180

const expiresAt = epochMs - (opts.bufferMs ?? 0);

181181

return Number.isSafeInteger(expiresAt) ? expiresAt : undefined;

182182

}

183+
184+

export function resolveExpiresAtMsFromDurationOrEpoch(

185+

value: unknown,

186+

opts: {

187+

nowMs?: number;

188+

relativeSecondsThreshold?: number;

189+

absoluteMillisecondsThreshold?: number;

190+

} = {},

191+

): number | undefined {

192+

const parsed = parseStrictPositiveInteger(value);

193+

if (parsed === undefined) {

194+

return undefined;

195+

}

196+

const relativeSecondsThreshold = opts.relativeSecondsThreshold ?? 1_000_000_000;

197+

if (parsed < relativeSecondsThreshold) {

198+

return resolveExpiresAtMsFromDurationSeconds(parsed, { nowMs: opts.nowMs });

199+

}

200+

const absoluteMillisecondsThreshold = opts.absoluteMillisecondsThreshold ?? 1_000_000_000_000;

201+

if (parsed < absoluteMillisecondsThreshold) {

202+

return positiveSecondsToSafeMilliseconds(parsed);

203+

}

204+

return parsed;

205+

}