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

推荐订阅源

J
Java Code Geeks
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
B
Blog
aimingoo的专栏
aimingoo的专栏
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
月光博客
月光博客
H
Help Net Security
V
Visual Studio Blog
量子位
A
About on SuperTechFans
博客园 - Franky
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | 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(msteams): validate oauth token lifetimes · openclaw/o...
steipete · 2026-05-30 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -247,6 +247,25 @@ describe("exchangeMSTeamsCodeForTokens", () => {

247247

}),

248248

).rejects.toThrow("MSTeams token exchange failed: malformed JSON response");

249249

});

250+
251+

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

252+

fetchSpy.mockResolvedValueOnce(

253+

new Response('{"access_token":"at-unsafe","refresh_token":"rt-unsafe","expires_in":1e309}', {

254+

status: 200,

255+

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

256+

}),

257+

);

258+
259+

await expect(

260+

exchangeMSTeamsCodeForTokens({

261+

tenantId: "t",

262+

clientId: "c",

263+

clientSecret: "s", // pragma: allowlist secret

264+

code: "unsafe-expiry",

265+

verifier: "v",

266+

}),

267+

).rejects.toThrow("MSTeams token exchange failed: invalid token response fields");

268+

});

250269

});

251270
252271

describe("refreshMSTeamsDelegatedTokens", () => {

Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

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

12

import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";

23

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

34

import { createMSTeamsHttpError } from "./http-error.js";

@@ -15,7 +16,7 @@ const EXPIRY_BUFFER_MS = 5 * 60 * 1000;

1516

type MSTeamsTokenResponse = {

1617

access_token: string;

1718

refresh_token?: string;

18-

expires_in: number;

19+

expiresAt: number;

1920

scope?: string;

2021

};

2122

@@ -40,6 +41,42 @@ function createMSTeamsTokenBody(params: {

4041

return body;

4142

}

4243
44+

function resolveMSTeamsTokenExpiresAt(value: unknown): number | undefined {

45+

const expiresInSeconds = parseStrictPositiveInteger(value);

46+

if (expiresInSeconds === undefined) {

47+

return undefined;

48+

}

49+
50+

const lifetimeMs = expiresInSeconds * 1000;

51+

const expiresAt = Date.now() + lifetimeMs - EXPIRY_BUFFER_MS;

52+

return Number.isSafeInteger(lifetimeMs) && Number.isSafeInteger(expiresAt)

53+

? expiresAt

54+

: undefined;

55+

}

56+
57+

function parseMSTeamsTokenResponse(

58+

data: Record<string, unknown>,

59+

failureLabel: string,

60+

): MSTeamsTokenResponse {

61+

const expiresAt = resolveMSTeamsTokenExpiresAt(data.expires_in);

62+

if (

63+

typeof data.access_token !== "string" ||

64+

!data.access_token ||

65+

expiresAt === undefined ||

66+

(data.refresh_token !== undefined && typeof data.refresh_token !== "string") ||

67+

(data.scope !== undefined && typeof data.scope !== "string")

68+

) {

69+

throw new Error(`MSTeams ${failureLabel} failed: invalid token response fields`);

70+

}

71+
72+

return {

73+

access_token: data.access_token,

74+

refresh_token: data.refresh_token,

75+

expiresAt,

76+

scope: data.scope,

77+

};

78+

}

79+
4380

async function fetchMSTeamsTokens(params: {

4481

tokenUrl: string;

4582

body: URLSearchParams;

@@ -66,10 +103,11 @@ async function fetchMSTeamsTokens(params: {

66103

if (!response.ok) {

67104

throw await createMSTeamsHttpError(response, `MSTeams ${params.failureLabel} failed`);

68105

}

69-

return await readProviderJsonResponse<MSTeamsTokenResponse>(

106+

const data = await readProviderJsonResponse<Record<string, unknown>>(

70107

response,

71108

`MSTeams ${params.failureLabel} failed`,

72109

);

110+

return parseMSTeamsTokenResponse(data, params.failureLabel);

73111

} finally {

74112

await release();

75113

}

@@ -104,7 +142,7 @@ async function requestMSTeamsDelegatedTokens(params: {

104142

return {

105143

accessToken: data.access_token,

106144

refreshToken: params.resolveRefreshToken(data),

107-

expiresAt: Date.now() + data.expires_in * 1000 - EXPIRY_BUFFER_MS,

145+

expiresAt: data.expiresAt,

108146

scopes: data.scope ? data.scope.split(" ") : [...scopes],

109147

};

110148

}