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

推荐订阅源

Recent Announcements
Recent Announcements
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
博客园_首页
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
Jina AI
Jina AI
月光博客
月光博客
小众软件
小众软件
S
SegmentFault 最新的问题
量子位
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

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(auth): avoid keychain creation for oauth profile secr...
vincentkoc · 2026-05-17 · via Recent Commits to openclaw:main

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

1-

import { execFileSync } from "node:child_process";

1+

import * as childProcess from "node:child_process";

22

import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";

33

import fs from "node:fs";

44

import os from "node:os";

@@ -73,6 +73,16 @@ type LoadPersistedAuthProfileStoreOptions = {

7373

repairOAuthSecretPayloads?: boolean;

7474

};

757576+

type OAuthProfileSecretKeySeedOptions = { create?: boolean };

77+78+

type OAuthProfileSecretKeySeedDeps = {

79+

env: NodeJS.ProcessEnv;

80+

platform: NodeJS.Platform;

81+

readMacKeychain: () => string | undefined;

82+

readFile: () => string | undefined;

83+

createFile: () => string | undefined;

84+

};

85+7686

function isRecord(value: unknown): value is Record<string, unknown> {

7787

return !!value && typeof value === "object" && !Array.isArray(value);

7888

}

@@ -304,7 +314,7 @@ function readMacOAuthProfileSecretKey(): string | undefined {

304314

return undefined;

305315

}

306316

try {

307-

return execFileSync(

317+

return childProcess.execFileSync(

308318

"security",

309319

[

310320

"find-generic-password",

@@ -321,33 +331,6 @@ function readMacOAuthProfileSecretKey(): string | undefined {

321331

}

322332

}

323333324-

function createMacOAuthProfileSecretKey(): string | undefined {

325-

if (process.platform !== "darwin") {

326-

return undefined;

327-

}

328-

const generated = randomBytes(32).toString("base64url");

329-

try {

330-

execFileSync(

331-

"security",

332-

[

333-

"add-generic-password",

334-

"-U",

335-

"-s",

336-

OAUTH_PROFILE_SECRET_KEYCHAIN_SERVICE,

337-

"-a",

338-

OAUTH_PROFILE_SECRET_KEYCHAIN_ACCOUNT,

339-

"-w",

340-

generated,

341-

],

342-

{ encoding: "utf8", timeout: 5000, stdio: ["pipe", "pipe", "pipe"] },

343-

);

344-

return generated;

345-

} catch (err) {

346-

log.warn("failed to create oauth profile secret keychain entry", { err });

347-

return undefined;

348-

}

349-

}

350-351334

function isPathInsideOrEqual(parentDir: string, candidatePath: string): boolean {

352335

const relative = path.relative(path.resolve(parentDir), path.resolve(candidatePath));

353336

return (

@@ -459,39 +442,53 @@ function createFallbackOAuthProfileSecretKeyFile(): string | undefined {

459442

}

460443

}

461444462-

function shouldUseMacKeychainForOAuthProfileSecrets(): boolean {

445+

function shouldReadMacKeychainForOAuthProfileSecrets(params?: {

446+

env?: NodeJS.ProcessEnv;

447+

platform?: NodeJS.Platform;

448+

}): boolean {

449+

const env = params?.env ?? process.env;

450+

const platform = params?.platform ?? process.platform;

463451

return (

464-

process.platform === "darwin" &&

465-

process.env.VITEST !== "true" &&

466-

process.env.VITEST_WORKER_ID === undefined

452+

platform === "darwin" && env.VITEST !== "true" && env.VITEST_WORKER_ID === undefined

467453

);

468454

}

469455470-

function resolveOAuthProfileSecretKeySeed(options?: { create?: boolean }): string | undefined {

471-

const externalKey = process.env[OAUTH_PROFILE_SECRET_KEY_ENV]?.trim();

456+

function resolveOAuthProfileSecretKeySeedWithDeps(

457+

options: OAuthProfileSecretKeySeedOptions | undefined,

458+

deps: OAuthProfileSecretKeySeedDeps,

459+

): string | undefined {

460+

const externalKey = deps.env[OAUTH_PROFILE_SECRET_KEY_ENV]?.trim();

472461

if (externalKey) {

473462

return externalKey;

474463

}

475-

if (process.env.NODE_ENV === "test" && process.env.VITEST === "true") {

464+

if (deps.env.NODE_ENV === "test" && deps.env.VITEST === "true") {

476465

return "openclaw-test-oauth-profile-secret-key";

477466

}

478-

if (shouldUseMacKeychainForOAuthProfileSecrets()) {

479-

const keychainKey =

480-

readMacOAuthProfileSecretKey() ??

481-

(options?.create === true ? createMacOAuthProfileSecretKey() : undefined);

467+

if (shouldReadMacKeychainForOAuthProfileSecrets({ env: deps.env, platform: deps.platform })) {

468+

const keychainKey = deps.readMacKeychain();

482469

if (keychainKey) {

483470

return keychainKey;

484471

}

485472

}

486-

const fileKey =

487-

readFallbackOAuthProfileSecretKeyFile() ??

488-

(options?.create === true ? createFallbackOAuthProfileSecretKeyFile() : undefined);

473+

const fileKey = deps.readFile() ?? (options?.create === true ? deps.createFile() : undefined);

489474

if (fileKey) {

490475

return fileKey;

491476

}

492477

return undefined;

493478

}

494479480+

function resolveOAuthProfileSecretKeySeed(

481+

options?: OAuthProfileSecretKeySeedOptions,

482+

): string | undefined {

483+

return resolveOAuthProfileSecretKeySeedWithDeps(options, {

484+

env: process.env,

485+

platform: process.platform,

486+

readMacKeychain: readMacOAuthProfileSecretKey,

487+

readFile: readFallbackOAuthProfileSecretKeyFile,

488+

createFile: createFallbackOAuthProfileSecretKeyFile,

489+

});

490+

}

491+495492

function buildOAuthProfileSecretKey(options?: { create?: boolean }): Buffer | null {

496493

const externalKey = resolveOAuthProfileSecretKeySeed(options);

497494

if (!externalKey) {

@@ -500,6 +497,11 @@ function buildOAuthProfileSecretKey(options?: { create?: boolean }): Buffer | nu

500497

return createHash("sha256").update(`openclaw:auth-profile-oauth:${externalKey}`).digest();

501498

}

502499500+

export const __testing = {

501+

resolveOAuthProfileSecretKeySeedWithDeps,

502+

shouldReadMacKeychainForOAuthProfileSecrets,

503+

};

504+503505

function encryptOAuthProfileSecretMaterial(params: {

504506

ref: OAuthCredentialRef;

505507

profileId: string;