skillmkt 0.4.36 → 0.4.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/commands/audit.js +18 -4
- package/client/lib/audit.js +21 -10
- package/client/lib/ctx.js +1 -1
- package/client/lib/help.js +6 -3
- package/package.json +1 -1
package/client/commands/audit.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
// audit [name|--all] — 重跑静态审核刷新 scans/;--llm 附加语义审(批次6 全量)
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
-
import { auditDir, writeScan } from '../lib/audit.js';
|
|
4
|
+
import { auditDir, writeScan, verdictOf, RULE_IDS } from '../lib/audit.js';
|
|
5
5
|
import { llmAudit } from '../lib/ai.js';
|
|
6
6
|
import { walk } from '../lib/package.js';
|
|
7
7
|
import { ok, warn, fail, info, auditTag } from '../lib/render.js';
|
|
8
|
+
import { readLibrary, writeLibrary } from '../lib/hub.js';
|
|
9
|
+
import { readYAML } from '../../pipeline/lib/util.js';
|
|
8
10
|
import { L } from '../lib/i18n.js';
|
|
9
11
|
|
|
10
12
|
export async function run(ctx) {
|
|
11
13
|
const flags = ctx.flags.raw;
|
|
12
14
|
const skills = ctx.library.skills || {};
|
|
15
|
+
if (flags.allow && !RULE_IDS.includes(flags.allow)) { fail(L(`未知规则 id: ${flags.allow}(可选: ${RULE_IDS.join(' ')})`, `unknown rule id: ${flags.allow} (one of: ${RULE_IDS.join(' ')})`)); return 1; }
|
|
13
16
|
if (flags.all && ctx.args.length) { fail(L('--all 和指定名字只能二选一', '--all and specific names are mutually exclusive')); return 1; }
|
|
14
17
|
const names = flags.all ? Object.keys(skills) : ctx.args;
|
|
15
|
-
if (!names.length) { fail(L('用法: skillmkt audit <名字|--all> [--llm]', 'usage: skillmkt audit <name|--all> [--llm]')); return 1; }
|
|
18
|
+
if (!names.length) { fail(L('用法: skillmkt audit <名字|--all> [--llm] [--allow <规则id>]', 'usage: skillmkt audit <name|--all> [--llm] [--allow <rule-id>]')); return 1; }
|
|
16
19
|
let worst = 'clean';
|
|
17
20
|
const order = { clean: 0, suspicious: 1, stripped: 1, malicious: 2 };
|
|
18
21
|
for (const name of names) {
|
|
@@ -27,9 +30,20 @@ export async function run(ctx) {
|
|
|
27
30
|
if (lr) { r.llm = lr; info(` llm: ${lr.verdict}${lr.reasons?.length ? ` — ${lr.reasons.join('; ')}` : ''}`); }
|
|
28
31
|
else warn(L(' LLM 审核不可用——沿用静态检查结论', ' llm audit unavailable — keeping static verdict'));
|
|
29
32
|
}
|
|
30
|
-
|
|
33
|
+
// 豁免:历史 allow + 本次 --allow;豁免的 finding 标 allowed 不定罪但留档
|
|
34
|
+
const old = readYAML(path.join(ctx.hub, 'scans', `${name}.yml`)) || {};
|
|
35
|
+
const allow = [...new Set([...(old.allow || []), ...(flags.allow ? [flags.allow] : [])])];
|
|
36
|
+
for (const f of r.findings) if (allow.includes(f.rule)) f.allowed = true;
|
|
37
|
+
r.verdict = verdictOf(r.findings, r.stripped);
|
|
38
|
+
writeScan(ctx.hub, name, r, { llm: r.llm || null, allow });
|
|
39
|
+
// library 里的审核标记跟着最新结论走
|
|
40
|
+
if (skills[name] && skills[name].audit !== r.verdict) {
|
|
41
|
+
const lib = readLibrary(ctx.hub);
|
|
42
|
+
if (lib.skills?.[name]) { lib.skills[name].audit = r.verdict; writeLibrary(ctx.hub, lib); }
|
|
43
|
+
}
|
|
31
44
|
if (order[r.verdict] > order[worst]) worst = r.verdict;
|
|
32
|
-
|
|
45
|
+
const waived = r.findings.filter((f) => f.doc || f.allowed).length;
|
|
46
|
+
info(`${name}: ${auditTag(r.verdict)}${r.findings.length ? L(`(${r.findings.length} 处发现${waived ? `,${waived} 处豁免` : ''})`, ` (${r.findings.length} findings${waived ? `, ${waived} waived` : ''})`) : ''}`);
|
|
33
47
|
}
|
|
34
48
|
ok(L('审核完成', 'audit done'));
|
|
35
49
|
return worst === 'malicious' ? 2 : 0;
|
package/client/lib/audit.js
CHANGED
|
@@ -5,6 +5,9 @@ import { walk } from './package.js';
|
|
|
5
5
|
import { writeYAMLFile } from './hub.js';
|
|
6
6
|
|
|
7
7
|
const TEXT_EXT = /\.(md|txt|json|ya?ml|toml|mjs|cjs|js|ts|sh|py|html?|css)$/i;
|
|
8
|
+
const DOC_EXT = /\.(md|markdown|txt|rst|adoc)$/i;
|
|
9
|
+
// 文档语境豁免只对"下载型"curl 生效——真危险的是这些(管道执行/反弹shell/编码绕过)
|
|
10
|
+
const EGRESS_DANGER = /\|\s*(?:sudo\s+)?(?:ba|z)?sh\b|\bnc\b\s+-|\/dev\/tcp\/|\bbase64\b/i;
|
|
8
11
|
const STRIP_DIRS = /^(scripts?|bin|tools?|hooks?|install|\.github\/workflows)$/i;
|
|
9
12
|
const EXEC_EXT = /\.(sh|bash|zsh|exe|bat|cmd|ps1|com|dll|so|dylib|app)$/i;
|
|
10
13
|
|
|
@@ -52,23 +55,30 @@ export function auditDir(dir, { strip = true } = {}) {
|
|
|
52
55
|
lines.forEach((line, i) => {
|
|
53
56
|
if (rule.re.test(line)) {
|
|
54
57
|
const severe = rule.severe === true ? true : !!rule.severe?.test?.(line);
|
|
55
|
-
|
|
58
|
+
// 文档里的"下载型"curl 降级为 doc——记录但不单独定罪(维护说明/用户手册常见)
|
|
59
|
+
const doc = rule.id === 'egress-cmd' && DOC_EXT.test(base) && !EGRESS_DANGER.test(line);
|
|
60
|
+
findings.push({ rule: rule.id, file: rel, line: i + 1, excerpt: line.trim().slice(0, 120), severe, ...(doc ? { doc: true } : {}) });
|
|
56
61
|
}
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const severe = findings.some((f) => f.severe);
|
|
64
|
-
const suspiciousCount = findings.reduce((n, f) => n + (RULES.find((r) => r.id === f.rule)?.weight ?? 1), 0);
|
|
65
|
-
let verdict = 'clean';
|
|
66
|
-
if (has('pii-harvest') || severe || (has('secret-pattern') && has('egress-cmd')) || suspiciousCount >= 5) verdict = 'malicious';
|
|
67
|
-
else if (findings.length || stripped.length) verdict = 'suspicious';
|
|
66
|
+
return { verdict: verdictOf(findings, stripped), findings, stripped: strip ? stripped : [] };
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
// verdict 归并(代码判定,不是模型)。doc=文档语境误报,allowed=用户人工豁免——都不定罪但仍记录
|
|
70
|
+
export function verdictOf(findings, stripped = []) {
|
|
71
|
+
const live = findings.filter((f) => !f.doc && !f.allowed);
|
|
72
|
+
const has = (id) => live.some((f) => f.rule === id);
|
|
73
|
+
const severe = live.some((f) => f.severe);
|
|
74
|
+
const suspiciousCount = live.reduce((n, f) => n + (RULES.find((r) => r.id === f.rule)?.weight ?? 1), 0);
|
|
75
|
+
if (has('pii-harvest') || severe || (has('secret-pattern') && has('egress-cmd')) || suspiciousCount >= 5) return 'malicious';
|
|
76
|
+
if (live.length || stripped.length) return 'suspicious';
|
|
77
|
+
return 'clean';
|
|
70
78
|
}
|
|
71
79
|
|
|
80
|
+
export const RULE_IDS = RULES.map((r) => r.id);
|
|
81
|
+
|
|
72
82
|
// 剥离:copy 时排除 stripped 相对路径
|
|
73
83
|
export function stripFilter(stripped) {
|
|
74
84
|
const set = new Set(stripped);
|
|
@@ -76,12 +86,13 @@ export function stripFilter(stripped) {
|
|
|
76
86
|
return (rel) => !set.has(rel) && !tops.has(rel.split('/')[0]);
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
export function writeScan(hub, name, result, { llm = null } = {}) {
|
|
89
|
+
export function writeScan(hub, name, result, { llm = null, allow = [] } = {}) {
|
|
80
90
|
writeYAMLFile(path.join(hub, 'scans', `${name}.yml`), {
|
|
81
91
|
name,
|
|
82
92
|
scanned_at: new Date().toISOString(),
|
|
83
93
|
static: { findings: result.findings, stripped: result.stripped },
|
|
84
94
|
verdict: result.verdict,
|
|
95
|
+
...(allow.length ? { allow } : {}),
|
|
85
96
|
...(llm ? { llm } : {}),
|
|
86
97
|
});
|
|
87
98
|
}
|
package/client/lib/ctx.js
CHANGED
|
@@ -4,7 +4,7 @@ import { detectHarnesses, detectProject } from './scanner.js';
|
|
|
4
4
|
import { resolveLLM } from './llm.js';
|
|
5
5
|
import { setUILang } from './i18n.js';
|
|
6
6
|
|
|
7
|
-
const VALUE_FLAGS = new Set(['hub', 'base-url', 'model', 'api-key-env', 'from', 'to', 'target', 'scope', 'path', 'registry', 'name', 'resolution', 'reason', 'custom', 'port', 'project', 'type', 'url', 'token', 'out', 'limit', 'policy']);
|
|
7
|
+
const VALUE_FLAGS = new Set(['hub', 'base-url', 'model', 'api-key-env', 'from', 'to', 'target', 'scope', 'path', 'registry', 'name', 'resolution', 'reason', 'custom', 'port', 'project', 'type', 'url', 'token', 'out', 'limit', 'policy', 'allow']);
|
|
8
8
|
const BOOL_FLAGS = new Set(['json', 'verbose', 'no-llm', 'dry-run', 'ui', 'cli', 'no-ui', 'yes', 'y', 'help', 'h', 'version', 'V', 'force', 'all', 'llm', 'semantic', 'raw', 'files', 'rules', 'audit-only', 'purge', 'link', 'remote', 'local', 'wait', 'stop', 'daemon', 'keep-scripts', 'report', 'check', 'once', 'scan', 'evidence', 'auto']);
|
|
9
9
|
|
|
10
10
|
export function parseArgv(argv) {
|
package/client/lib/help.js
CHANGED
|
@@ -118,12 +118,15 @@ const H = {
|
|
|
118
118
|
--dry-run reports without writing (also lists newly detected agents).`,
|
|
119
119
|
},
|
|
120
120
|
audit: {
|
|
121
|
-
zh: `用法: skillmkt audit <名字|--all> [--llm] [--json]
|
|
121
|
+
zh: `用法: skillmkt audit <名字|--all> [--llm] [--allow <规则id>] [--json]
|
|
122
122
|
安全审核:scripts/密钥模式/外联指令等确定性检查;--llm 追加本地模型分析。
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
--allow 豁免误报规则(该 skill 的重审/升级都认;规则 id: egress-cmd 等)。
|
|
124
|
+
文档里的下载型 curl 自动降级不计罪。结论词:干净 / 可疑 / 已剔除 / 恶意 / 已隔离。`,
|
|
125
|
+
en: `usage: skillmkt audit <name|--all> [--llm] [--allow <rule-id>] [--json]
|
|
125
126
|
Security audit: deterministic checks for scripts/secret patterns/outbound
|
|
126
127
|
instructions; --llm adds local-model analysis.
|
|
128
|
+
--allow suppresses a false-positive rule (sticks across re-audits/upgrades).
|
|
129
|
+
Download-style curl in docs is downgraded automatically.
|
|
127
130
|
Verdicts: clean / suspicious / stripped / malicious / quarantined.`,
|
|
128
131
|
},
|
|
129
132
|
update: {
|