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

推荐订阅源

Recent Announcements
Recent Announcements
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
A
About on SuperTechFans
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
B
Blog RSS Feed
G
Google Developers Blog
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)

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
test(plugins): scan publishable npm packages · openclaw/o...
vincentkoc · 2026-05-03 · via Recent Commits to openclaw:main

@@ -0,0 +1,114 @@

1+

import { execFileSync } from "node:child_process";

2+

import { copyFileSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";

3+

import { tmpdir } from "node:os";

4+

import { dirname, join, relative, resolve, sep } from "node:path";

5+

import { afterEach, describe, expect, it } from "vitest";

6+

import { withAugmentedPluginNpmManifestForPackage } from "../../scripts/lib/plugin-npm-package-manifest.mjs";

7+

import { collectPublishablePluginPackages } from "../../scripts/lib/plugin-npm-release.ts";

8+

import { isScannable, scanDirectoryWithSummary } from "../security/skill-scanner.js";

9+10+

type NpmPackFile = {

11+

path?: unknown;

12+

};

13+14+

type NpmPackResult = {

15+

files?: unknown;

16+

};

17+18+

const tempDirs: string[] = [];

19+20+

afterEach(() => {

21+

for (const dir of tempDirs.splice(0)) {

22+

rmSync(dir, { recursive: true, force: true });

23+

}

24+

});

25+26+

function parseNpmPackFiles(raw: string, packageName: string): string[] {

27+

const parsed = JSON.parse(raw) as unknown;

28+

if (!Array.isArray(parsed) || parsed.length !== 1) {

29+

throw new Error(`${packageName}: npm pack --dry-run did not return one package result.`);

30+

}

31+32+

const result = parsed[0] as NpmPackResult;

33+

if (!Array.isArray(result.files)) {

34+

throw new Error(`${packageName}: npm pack --dry-run did not return a files list.`);

35+

}

36+37+

return result.files

38+

.map((entry) => (entry as NpmPackFile).path)

39+

.filter((packedPath): packedPath is string => typeof packedPath === "string")

40+

.toSorted();

41+

}

42+43+

function collectNpmPackedFiles(packageDir: string, packageName: string): string[] {

44+

return withAugmentedPluginNpmManifestForPackage({ packageDir }, ({ packageDir: cwd }) => {

45+

const raw = execFileSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], {

46+

cwd,

47+

encoding: "utf8",

48+

maxBuffer: 128 * 1024 * 1024,

49+

stdio: ["ignore", "pipe", "pipe"],

50+

});

51+

return parseNpmPackFiles(raw, packageName);

52+

});

53+

}

54+55+

function isScannerWalkedPackedPath(packedPath: string): boolean {

56+

return (

57+

isScannable(packedPath) &&

58+

packedPath.split(/[\\/]/).every((segment) => {

59+

return segment.length > 0 && segment !== "node_modules" && !segment.startsWith(".");

60+

})

61+

);

62+

}

63+64+

function stageScannerRelevantPackedFiles(

65+

packageDir: string,

66+

packedFiles: readonly string[],

67+

): string {

68+

const stageDir = mkdtempSync(join(tmpdir(), "openclaw-plugin-npm-scan-"));

69+

tempDirs.push(stageDir);

70+71+

for (const packedPath of packedFiles) {

72+

if (!isScannerWalkedPackedPath(packedPath)) {

73+

continue;

74+

}

75+76+

const source = resolve(packageDir, packedPath);

77+

const target = join(stageDir, ...packedPath.split(/[\\/]/));

78+

mkdirSync(dirname(target), { recursive: true });

79+

copyFileSync(source, target);

80+

}

81+82+

return stageDir;

83+

}

84+85+

describe("publishable plugin npm package install security scan", () => {

86+

it("keeps npm-published plugin files clear of env-harvesting hits", async () => {

87+

const failures: string[] = [];

88+89+

for (const plugin of collectPublishablePluginPackages()) {

90+

const packedFiles = collectNpmPackedFiles(plugin.packageDir, plugin.packageName);

91+

const stageDir = stageScannerRelevantPackedFiles(plugin.packageDir, packedFiles);

92+

const summary = await scanDirectoryWithSummary(stageDir, {

93+

excludeTestFiles: true,

94+

maxFiles: 10_000,

95+

});

96+97+

for (const finding of summary.findings) {

98+

if (finding.ruleId !== "env-harvesting" || finding.severity !== "critical") {

99+

continue;

100+

}

101+

failures.push(

102+

[

103+

plugin.packageName,

104+

relative(stageDir, finding.file).split(sep).join("/"),

105+

`${finding.line}`,

106+

finding.evidence,

107+

].join(":"),

108+

);

109+

}

110+

}

111+112+

expect(failures).toEqual([]);

113+

});

114+

});