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

推荐订阅源

罗磊的独立博客
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
D
DataBreaches.Net
B
Blog
博客园 - 【当耐特】
爱范儿
爱范儿
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
WordPress大学
WordPress大学
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
I
InfoQ
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
雷峰网
雷峰网
量子位
G
Google Developers 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: harden managed plugin peer recovery · openclaw/openc...
shakkernerd · 2026-05-13 · via Recent Commits to openclaw:main

@@ -29,6 +29,11 @@ type ManagedNpmRootOpenClawMetadata = {

2929

[key: string]: unknown;

3030

};

313132+

export type ManagedNpmRootPeerDependencySnapshot = {

33+

dependencies: Record<string, string>;

34+

managedPeerDependencies: string[];

35+

};

36+3237

export type ManagedNpmRootInstalledDependency = {

3338

version?: string;

3439

integrity?: string;

@@ -47,6 +52,16 @@ type ManagedNpmRootLogger = {

47524853

type ManagedNpmRootRunCommand = typeof runCommandWithTimeout;

495455+

type ManagedNpmPeerTraversalLimits = {

56+

maxDepth: number;

57+

maxDirectories: number;

58+

};

59+60+

const DEFAULT_MANAGED_NPM_PEER_TRAVERSAL_LIMITS: ManagedNpmPeerTraversalLimits = {

61+

maxDepth: 64,

62+

maxDirectories: 10_000,

63+

};

64+5065

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

5166

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

5267

}

@@ -68,6 +83,47 @@ function readDependencyRecord(value: unknown): Record<string, string> {

6883

return dependencies;

6984

}

708586+

function readPositiveIntegerEnv(name: string, fallback: number): number {

87+

const rawValue = process.env[name];

88+

if (!rawValue) {

89+

return fallback;

90+

}

91+

const parsedValue = Number.parseInt(rawValue, 10);

92+

return Number.isFinite(parsedValue) && parsedValue >= 1 ? parsedValue : fallback;

93+

}

94+95+

function resolveManagedNpmPeerTraversalLimits(): ManagedNpmPeerTraversalLimits {

96+

return {

97+

maxDepth: readPositiveIntegerEnv(

98+

"OPENCLAW_INSTALL_SCAN_MAX_DEPTH",

99+

DEFAULT_MANAGED_NPM_PEER_TRAVERSAL_LIMITS.maxDepth,

100+

),

101+

maxDirectories: readPositiveIntegerEnv(

102+

"OPENCLAW_INSTALL_SCAN_MAX_DIRECTORIES",

103+

DEFAULT_MANAGED_NPM_PEER_TRAVERSAL_LIMITS.maxDirectories,

104+

),

105+

};

106+

}

107+108+

function isSamePathOrInside(parentPath: string, candidatePath: string): boolean {

109+

const relative = path.relative(parentPath, candidatePath);

110+

return (

111+

relative === "" || (!!relative && !relative.startsWith("..") && !path.isAbsolute(relative))

112+

);

113+

}

114+115+

function isSafePackageName(name: string): boolean {

116+

if (name.startsWith("@")) {

117+

const parts = name.split("/");

118+

return (

119+

parts.length === 2 && parts.every((part) => part.length > 0 && part !== "." && part !== "..")

120+

);

121+

}

122+

return (

123+

name.length > 0 && !name.includes("/") && !name.includes("\\") && name !== "." && name !== ".."

124+

);

125+

}

126+71127

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

72128

if (!isRecord(value)) {

73129

return {};

@@ -301,7 +357,7 @@ async function listNodeModulesPackageDirs(nodeModulesDir: string): Promise<strin

301357

}

302358

const packageDirs: string[] = [];

303359

for (const entry of entries.toSorted((left, right) => left.name.localeCompare(right.name))) {

304-

if (entry.name === ".bin" || entry.name.startsWith(".")) {

360+

if (entry.name === ".bin" || entry.name === "openclaw" || entry.name.startsWith(".")) {

305361

continue;

306362

}

307363

const entryPath = path.join(nodeModulesDir, entry.name);

@@ -338,20 +394,50 @@ async function collectManagedNpmRootPeerDependencyPins(params: {

338394

npmRoot: string;

339395

}): Promise<Record<string, string>> {

340396

const pins = new Map<string, string>();

341-

const queue = await listNodeModulesPackageDirs(path.join(params.npmRoot, "node_modules"));

397+

const limits = resolveManagedNpmPeerTraversalLimits();

398+

const boundaryRealPath = await fs

399+

.realpath(params.npmRoot)

400+

.catch(() => path.resolve(params.npmRoot));

401+

const queue = (await listNodeModulesPackageDirs(path.join(params.npmRoot, "node_modules"))).map(

402+

(packageDir) => ({ depth: 0, packageDir }),

403+

);

404+

const visitedRealPaths = new Set<string>();

342405

for (let index = 0; index < queue.length; index += 1) {

343-

const packageDir = queue[index];

344-

if (!packageDir) {

406+

const current = queue[index];

407+

if (!current) {

408+

continue;

409+

}

410+

if (current.depth > limits.maxDepth) {

411+

throw new Error(

412+

`managed npm peer dependency scan exceeded max depth (${limits.maxDepth}) at ${current.packageDir}`,

413+

);

414+

}

415+

const packageDirRealPath = await fs

416+

.realpath(current.packageDir)

417+

.catch(() => path.resolve(current.packageDir));

418+

if (!isSamePathOrInside(boundaryRealPath, packageDirRealPath)) {

419+

throw new Error(

420+

`managed npm peer dependency scan found package outside managed npm root at ${current.packageDir}`,

421+

);

422+

}

423+

if (visitedRealPaths.has(packageDirRealPath)) {

345424

continue;

346425

}

426+

visitedRealPaths.add(packageDirRealPath);

427+

if (visitedRealPaths.size > limits.maxDirectories) {

428+

throw new Error(

429+

`managed npm peer dependency scan exceeded max packages (${limits.maxDirectories}) under ${params.npmRoot}`,

430+

);

431+

}

432+

const packageDir = current.packageDir;

347433

const manifest = await readPackageJsonIfExists(packageDir);

348434

if (manifest) {

349435

if (readOptionalString(manifest.name) === "openclaw") {

350436

continue;

351437

}

352438

const peerDependencies = readDependencyRecord(manifest.peerDependencies);

353439

for (const [peerName, peerRange] of Object.entries(peerDependencies)) {

354-

if (peerName === "openclaw" || pins.has(peerName)) {

440+

if (peerName === "openclaw" || pins.has(peerName) || !isSafePackageName(peerName)) {

355441

continue;

356442

}

357443

const installedVersion = await readPackageVersion(

@@ -363,13 +449,69 @@ async function collectManagedNpmRootPeerDependencyPins(params: {

363449

pins.set(peerName, installedVersion ?? peerRange);

364450

}

365451

}

366-

queue.push(...(await listNodeModulesPackageDirs(path.join(packageDir, "node_modules"))));

452+

queue.push(

453+

...(await listNodeModulesPackageDirs(path.join(packageDir, "node_modules"))).map(

454+

(nestedPackageDir) => ({

455+

depth: current.depth + 1,

456+

packageDir: nestedPackageDir,

457+

}),

458+

),

459+

);

367460

}

368461

return Object.fromEntries(

369462

[...pins.entries()].toSorted(([left], [right]) => left.localeCompare(right)),

370463

);

371464

}

372465466+

export async function readManagedNpmRootPeerDependencySnapshot(params: {

467+

npmRoot: string;

468+

}): Promise<ManagedNpmRootPeerDependencySnapshot> {

469+

const manifest = await readManagedNpmRootManifest(path.join(params.npmRoot, "package.json"));

470+

const dependencies = readDependencyRecord(manifest.dependencies);

471+

const managedPeerDependencies = readManagedPeerDependencyKeys(manifest.openclaw).toSorted();

472+

const dependencySnapshot: Record<string, string> = {};

473+

for (const packageName of managedPeerDependencies) {

474+

const dependencySpec = dependencies[packageName];

475+

if (dependencySpec) {

476+

dependencySnapshot[packageName] = dependencySpec;

477+

}

478+

}

479+

return {

480+

dependencies: dependencySnapshot,

481+

managedPeerDependencies,

482+

};

483+

}

484+485+

export async function restoreManagedNpmRootPeerDependencySnapshot(params: {

486+

npmRoot: string;

487+

snapshot: ManagedNpmRootPeerDependencySnapshot;

488+

}): Promise<void> {

489+

const manifestPath = path.join(params.npmRoot, "package.json");

490+

const manifest = await readManagedNpmRootManifest(manifestPath);

491+

const dependencies = readDependencyRecord(manifest.dependencies);

492+

for (const packageName of readManagedPeerDependencyKeys(manifest.openclaw)) {

493+

delete dependencies[packageName];

494+

}

495+

Object.assign(dependencies, params.snapshot.dependencies);

496+

const managedOverrideKeys = readManagedOverrideKeys(manifest.openclaw).toSorted();

497+

const openclawMetadata = buildManagedOpenClawMetadata({

498+

current: manifest.openclaw,

499+

managedOverrideKeys,

500+

managedPeerDependencyKeys: params.snapshot.managedPeerDependencies.toSorted(),

501+

});

502+

const next: ManagedNpmRootManifest = {

503+

...manifest,

504+

private: true,

505+

dependencies,

506+

};

507+

if (openclawMetadata) {

508+

next.openclaw = openclawMetadata;

509+

} else {

510+

delete next.openclaw;

511+

}

512+

await writeJson(manifestPath, next, { trailingNewline: true });

513+

}

514+373515

export async function syncManagedNpmRootPeerDependencies(params: {

374516

npmRoot: string;

375517

managedOverrides?: Record<string, unknown>;