@rafter-security/cli 0.8.7 → 0.8.10
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/dist/commands/agent/audit-skill.js +82 -6
- package/dist/commands/agent/components.js +3 -1
- package/dist/commands/agent/config.js +12 -4
- package/dist/commands/agent/exec.js +16 -13
- package/dist/commands/agent/index.js +4 -0
- package/dist/commands/agent/init.js +42 -1
- package/dist/commands/agent/remove-skill-scanner.js +16 -0
- package/dist/commands/agent/scan.js +35 -71
- package/dist/commands/agent/update-skill-scanner.js +40 -0
- package/dist/commands/hook/posttool.js +28 -5
- package/dist/commands/hook/pretool.js +37 -19
- package/dist/commands/mcp/server.js +9 -4
- package/dist/commands/skill/review.js +138 -5
- package/dist/core/command-interceptor.js +29 -3
- package/dist/core/config-manager.js +43 -4
- package/dist/core/risk-rules.js +14 -0
- package/dist/scanners/git-diff-scan.js +23 -0
- package/dist/scanners/regex-scanner.js +9 -0
- package/dist/scanners/skill-scanner.js +404 -0
- package/dist/utils/api.js +14 -1
- package/dist/utils/git-diff.js +85 -0
- package/package.json +4 -4
- package/resources/rafter-security-skill.md +1 -1
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional DEEP skill-review engine — wraps the external `skill-scanner` CLI.
|
|
3
|
+
*
|
|
4
|
+
* Parity with `python/rafter_cli/scanners/skill_scanner.py` (bead sable-7g7).
|
|
5
|
+
* This is the **couple, don't swap** integration: the zero-dependency
|
|
6
|
+
* deterministic quick scan stays the default for `rafter agent audit-skill`;
|
|
7
|
+
* passing `--deep` shells out to Cisco AI Defense's `skill-scanner`
|
|
8
|
+
* (pip: `cisco-ai-skill-scanner`) for a deeper pass covering prompt injection,
|
|
9
|
+
* taint/dataflow, YARA and .pyc integrity — the blind spots the regex quick
|
|
10
|
+
* scan cannot see.
|
|
11
|
+
*
|
|
12
|
+
* Design mirrors `betterleaks.ts`: an external tool both runtimes shell out to
|
|
13
|
+
* and whose JSON we parse. Critically, we invoke **only the offline/static
|
|
14
|
+
* default analyzers** (static + bytecode + pipeline). We never pass
|
|
15
|
+
* `--use-llm`, `--use-virustotal`, `--use-aidefense` or `--use-behavioral`, so
|
|
16
|
+
* nothing leaves the machine — preserving Rafter's offline / no-telemetry
|
|
17
|
+
* promise. The FORBIDDEN_FLAGS invariant is asserted by the vitest suite.
|
|
18
|
+
*
|
|
19
|
+
* Observed `skill-scanner` version: 2.0.11.
|
|
20
|
+
*/
|
|
21
|
+
import { execFile, execSync } from "child_process";
|
|
22
|
+
import { promisify } from "util";
|
|
23
|
+
import path from "path";
|
|
24
|
+
import fs from "fs";
|
|
25
|
+
import { askYesNo } from "../utils/prompt.js";
|
|
26
|
+
const execFileAsync = promisify(execFile);
|
|
27
|
+
/** PyPI package providing the external CLI, and the version we pin (mirrors
|
|
28
|
+
* SKILL_SCANNER_VERSION in the Python side / BETTERLEAKS_VERSION). */
|
|
29
|
+
export const SKILL_SCANNER_PACKAGE = "cisco-ai-skill-scanner";
|
|
30
|
+
export const SKILL_SCANNER_VERSION = "2.0.11";
|
|
31
|
+
/** skill-scanner severity (UPPERCASE) -> our tier (lowercase). skill-scanner
|
|
32
|
+
* also emits INFO, mapped to "low" (informational, e.g. missing-license). */
|
|
33
|
+
const SEVERITY_MAP = {
|
|
34
|
+
CRITICAL: "critical",
|
|
35
|
+
HIGH: "high",
|
|
36
|
+
MEDIUM: "medium",
|
|
37
|
+
LOW: "low",
|
|
38
|
+
INFO: "low",
|
|
39
|
+
};
|
|
40
|
+
/** Severities that count as actionable findings for exit-code purposes.
|
|
41
|
+
* INFO/low policy hints do NOT flip the exit code (matches the quick scan). */
|
|
42
|
+
const FINDING_SEVERITIES = new Set(["critical", "high", "medium"]);
|
|
43
|
+
/** Network/LLM/cloud flags that must NEVER appear in our argv. Enforced by a
|
|
44
|
+
* test so a regression that flips on a remote analyzer fails the suite. */
|
|
45
|
+
export const FORBIDDEN_FLAGS = [
|
|
46
|
+
"--use-llm",
|
|
47
|
+
"--use-virustotal",
|
|
48
|
+
"--use-aidefense",
|
|
49
|
+
"--use-behavioral",
|
|
50
|
+
"--vt-api-key",
|
|
51
|
+
"--aidefense-api-key",
|
|
52
|
+
];
|
|
53
|
+
export const INSTALL_HINT = "skill-scanner not found. The --deep engine requires Cisco AI Defense's " +
|
|
54
|
+
"skill-scanner. Install it with the managed installer:\n" +
|
|
55
|
+
" rafter agent update-skill-scanner\n" +
|
|
56
|
+
" (or manually: uv tool install cisco-ai-skill-scanner)\n" +
|
|
57
|
+
"Then re-run with --deep.";
|
|
58
|
+
export function hasFindings(result) {
|
|
59
|
+
return result.findings.some((f) => FINDING_SEVERITIES.has(f.severity));
|
|
60
|
+
}
|
|
61
|
+
export class SkillScanner {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.resolvedPath = null;
|
|
64
|
+
}
|
|
65
|
+
/** Locate the `skill-scanner` launcher on PATH (uv tool / pip --user both
|
|
66
|
+
* place it there). Cached after first lookup. */
|
|
67
|
+
resolvePath() {
|
|
68
|
+
if (this.resolvedPath !== null)
|
|
69
|
+
return this.resolvedPath || null;
|
|
70
|
+
const cmd = process.platform === "win32" ? "where skill-scanner" : "which skill-scanner";
|
|
71
|
+
try {
|
|
72
|
+
const result = execSync(cmd, { timeout: 5000, encoding: "utf-8" });
|
|
73
|
+
const found = result.trim().split("\n")[0].trim();
|
|
74
|
+
this.resolvedPath = found || "";
|
|
75
|
+
return found || null;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
this.resolvedPath = "";
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
isAvailable() {
|
|
83
|
+
return this.resolvePath() !== null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Construct the OFFLINE-SAFE argv for a skill-scanner scan.
|
|
87
|
+
*
|
|
88
|
+
* Guarantees (asserted by tests): no flag in FORBIDDEN_FLAGS is ever added,
|
|
89
|
+
* so only the default static/bytecode/pipeline analyzers run, all offline.
|
|
90
|
+
* `--format json` for a machine-parseable object; `--fail-on-severity medium`
|
|
91
|
+
* so the exit code reflects findings (skill-scanner otherwise exits 0 even on
|
|
92
|
+
* CRITICAL).
|
|
93
|
+
*/
|
|
94
|
+
static buildArgv(targetDir, opts = {}) {
|
|
95
|
+
const argv = [
|
|
96
|
+
"scan",
|
|
97
|
+
targetDir,
|
|
98
|
+
"--format",
|
|
99
|
+
"json",
|
|
100
|
+
"--fail-on-severity",
|
|
101
|
+
"medium",
|
|
102
|
+
];
|
|
103
|
+
if (opts.skillFile) {
|
|
104
|
+
argv.push("--skill-file", opts.skillFile);
|
|
105
|
+
}
|
|
106
|
+
if (opts.lenient) {
|
|
107
|
+
argv.push("--lenient");
|
|
108
|
+
}
|
|
109
|
+
return argv;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Run an offline deep scan for a skill file or directory. skill-scanner only
|
|
113
|
+
* scans a *directory*, so when given a file we scan its parent directory and
|
|
114
|
+
* point --skill-file at the filename (plus --lenient for robustness).
|
|
115
|
+
*/
|
|
116
|
+
async scanPath(skillPath) {
|
|
117
|
+
const binary = this.resolvePath();
|
|
118
|
+
if (!binary) {
|
|
119
|
+
return {
|
|
120
|
+
available: false,
|
|
121
|
+
findings: [],
|
|
122
|
+
maxSeverity: null,
|
|
123
|
+
analyzersUsed: [],
|
|
124
|
+
error: INSTALL_HINT,
|
|
125
|
+
raw: null,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
let targetDir;
|
|
129
|
+
let skillFile;
|
|
130
|
+
let lenient;
|
|
131
|
+
const isDir = fs.existsSync(skillPath) && fs.statSync(skillPath).isDirectory();
|
|
132
|
+
if (isDir) {
|
|
133
|
+
targetDir = skillPath;
|
|
134
|
+
skillFile = null;
|
|
135
|
+
lenient = false;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
targetDir = path.dirname(skillPath);
|
|
139
|
+
skillFile = path.basename(skillPath);
|
|
140
|
+
lenient = true;
|
|
141
|
+
}
|
|
142
|
+
const argv = SkillScanner.buildArgv(targetDir, { skillFile, lenient });
|
|
143
|
+
let stdout = "";
|
|
144
|
+
try {
|
|
145
|
+
const res = await execFileAsync(binary, argv, {
|
|
146
|
+
timeout: 120000,
|
|
147
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
148
|
+
});
|
|
149
|
+
stdout = (res.stdout || "").trim();
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
// skill-scanner exits non-zero (1) when findings hit the --fail-on-severity
|
|
153
|
+
// floor; the JSON report is still on stdout in that case. execFile rejects
|
|
154
|
+
// on non-zero exit, so recover stdout from the error object.
|
|
155
|
+
const err = e;
|
|
156
|
+
if (err.killed || err.signal === "SIGTERM") {
|
|
157
|
+
return errorResult("skill-scanner scan timed out");
|
|
158
|
+
}
|
|
159
|
+
stdout = (err.stdout || "").trim();
|
|
160
|
+
if (!stdout) {
|
|
161
|
+
return errorResult(`skill-scanner invocation failed: ${err.message || e}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!stdout) {
|
|
165
|
+
return errorResult("skill-scanner produced no JSON output");
|
|
166
|
+
}
|
|
167
|
+
let parsed;
|
|
168
|
+
try {
|
|
169
|
+
parsed = JSON.parse(stdout);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
return errorResult(`failed to parse skill-scanner JSON: ${e}`);
|
|
173
|
+
}
|
|
174
|
+
return SkillScanner.map(parsed);
|
|
175
|
+
}
|
|
176
|
+
static map(parsed) {
|
|
177
|
+
const rawFindings = Array.isArray(parsed.findings) ? parsed.findings : [];
|
|
178
|
+
const findings = rawFindings.map((f) => {
|
|
179
|
+
const rawSev = String(f.severity ?? "").toUpperCase();
|
|
180
|
+
const tier = SEVERITY_MAP[rawSev] ?? "low";
|
|
181
|
+
return {
|
|
182
|
+
ruleId: String(f.rule_id ?? f.id ?? "unknown"),
|
|
183
|
+
severity: tier,
|
|
184
|
+
category: String(f.category ?? ""),
|
|
185
|
+
title: String(f.title ?? ""),
|
|
186
|
+
description: String(f.description ?? ""),
|
|
187
|
+
file: f.file_path ?? null,
|
|
188
|
+
line: f.line_number ?? null,
|
|
189
|
+
snippet: f.snippet ?? null,
|
|
190
|
+
analyzer: String(f.analyzer ?? ""),
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
const rawMax = parsed.max_severity;
|
|
194
|
+
const maxSeverity = rawMax ? SEVERITY_MAP[String(rawMax).toUpperCase()] ?? null : null;
|
|
195
|
+
const analyzersUsed = Array.isArray(parsed.analyzers_used)
|
|
196
|
+
? parsed.analyzers_used
|
|
197
|
+
: [];
|
|
198
|
+
return {
|
|
199
|
+
available: true,
|
|
200
|
+
findings,
|
|
201
|
+
maxSeverity,
|
|
202
|
+
analyzersUsed,
|
|
203
|
+
error: "",
|
|
204
|
+
raw: parsed,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function errorResult(error) {
|
|
209
|
+
return {
|
|
210
|
+
available: true,
|
|
211
|
+
findings: [],
|
|
212
|
+
maxSeverity: null,
|
|
213
|
+
analyzersUsed: [],
|
|
214
|
+
error,
|
|
215
|
+
raw: null,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Managed installer for the optional `skill-scanner` deep engine.
|
|
220
|
+
*
|
|
221
|
+
* skill-scanner is a HEAVY PyPI package (litellm, fastapi, yara-x, …), so we
|
|
222
|
+
* install it ISOLATED rather than into any shared environment:
|
|
223
|
+
* 1. `uv tool install cisco-ai-skill-scanner==<version>` (preferred) — uv
|
|
224
|
+
* builds a dedicated venv and exposes a `skill-scanner` launcher on PATH.
|
|
225
|
+
* 2. Fallback `python3 -m pip install --user cisco-ai-skill-scanner==<version>`.
|
|
226
|
+
*
|
|
227
|
+
* Security posture (mirrors the betterleaks installer's intent): pinned version,
|
|
228
|
+
* list-form `execFile` (never a shell — no command injection), user-scoped, no
|
|
229
|
+
* elevation. Integrity relies on TLS-to-PyPI + the version pin (a single-binary
|
|
230
|
+
* SHA256 pin like betterleaks' is not possible over a pip transitive tree
|
|
231
|
+
* without a lockfile — documented limitation, not a regression).
|
|
232
|
+
*/
|
|
233
|
+
export class SkillScannerInstaller {
|
|
234
|
+
static uvPath() {
|
|
235
|
+
const cmd = process.platform === "win32" ? "where uv" : "which uv";
|
|
236
|
+
try {
|
|
237
|
+
const result = execSync(cmd, { timeout: 5000, encoding: "utf-8" });
|
|
238
|
+
const found = result.trim().split("\n")[0].trim();
|
|
239
|
+
return found || null;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** Construct the (list-form) install command + argv. Version is pinned with
|
|
246
|
+
* `==` so it can never be read as extra arguments. */
|
|
247
|
+
static buildInstall(version, uv) {
|
|
248
|
+
const spec = `${SKILL_SCANNER_PACKAGE}==${version}`;
|
|
249
|
+
if (uv) {
|
|
250
|
+
return { cmd: uv, argv: ["tool", "install", "--force", spec] };
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
cmd: process.platform === "win32" ? "python" : "python3",
|
|
254
|
+
argv: ["-m", "pip", "install", "--user", "--upgrade", spec],
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
async install(version = SKILL_SCANNER_VERSION, onProgress) {
|
|
258
|
+
const uv = SkillScannerInstaller.uvPath();
|
|
259
|
+
const via = uv ? "uv" : "pip";
|
|
260
|
+
const { cmd, argv } = SkillScannerInstaller.buildInstall(version, uv);
|
|
261
|
+
if (onProgress) {
|
|
262
|
+
onProgress(`Installing ${SKILL_SCANNER_PACKAGE}==${version} via ${via}…`);
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
await execFileAsync(cmd, argv, {
|
|
266
|
+
timeout: 900000, // heavy transitive tree; allow generous build time
|
|
267
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
const err = e;
|
|
272
|
+
const tail = (err.stderr || err.stdout || err.message || String(e)).trim().slice(-800);
|
|
273
|
+
return { ok: false, message: `installer failed: ${tail || "(no output)"}`, via };
|
|
274
|
+
}
|
|
275
|
+
// Verify the launcher is now reachable.
|
|
276
|
+
const checkCmd = process.platform === "win32" ? "where skill-scanner" : "which skill-scanner";
|
|
277
|
+
try {
|
|
278
|
+
const result = execSync(checkCmd, { timeout: 5000, encoding: "utf-8" });
|
|
279
|
+
const found = result.trim().split("\n")[0].trim();
|
|
280
|
+
if (found)
|
|
281
|
+
return { ok: true, message: found, via };
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
/* fall through */
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
ok: false,
|
|
288
|
+
message: "install reported success but `skill-scanner` is not on PATH. If you " +
|
|
289
|
+
"used the pip fallback, ensure your user-site bin directory is on PATH.",
|
|
290
|
+
via,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
static onPath() {
|
|
294
|
+
const cmd = process.platform === "win32" ? "where skill-scanner" : "which skill-scanner";
|
|
295
|
+
try {
|
|
296
|
+
return execSync(cmd, { timeout: 5000, encoding: "utf-8" }).trim().split("\n")[0].trim() || null;
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/** The (list-form) uninstall command. Mirrors install: uv tool, pip fallback. */
|
|
303
|
+
static buildUninstall(uv) {
|
|
304
|
+
if (uv) {
|
|
305
|
+
return { cmd: uv, argv: ["tool", "uninstall", SKILL_SCANNER_PACKAGE] };
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
cmd: process.platform === "win32" ? "python" : "python3",
|
|
309
|
+
argv: ["-m", "pip", "uninstall", "-y", SKILL_SCANNER_PACKAGE],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Remove the managed skill-scanner. Idempotent (a no-op success when not
|
|
314
|
+
* installed). Tries `uv tool uninstall` first (how install prefers to set it
|
|
315
|
+
* up), then a `pip uninstall` fallback — we don't durably record which path
|
|
316
|
+
* installed it.
|
|
317
|
+
*/
|
|
318
|
+
async uninstall(onProgress) {
|
|
319
|
+
if (!SkillScannerInstaller.onPath()) {
|
|
320
|
+
return { ok: true, message: "skill-scanner is not installed (nothing to do)", via: "" };
|
|
321
|
+
}
|
|
322
|
+
const uv = SkillScannerInstaller.uvPath();
|
|
323
|
+
const methods = [];
|
|
324
|
+
if (uv) {
|
|
325
|
+
const u = SkillScannerInstaller.buildUninstall(uv);
|
|
326
|
+
methods.push({ via: "uv", cmd: u.cmd, argv: u.argv });
|
|
327
|
+
}
|
|
328
|
+
const p = SkillScannerInstaller.buildUninstall(null);
|
|
329
|
+
methods.push({ via: "pip", cmd: p.cmd, argv: p.argv });
|
|
330
|
+
const attempts = [];
|
|
331
|
+
for (const m of methods) {
|
|
332
|
+
if (onProgress)
|
|
333
|
+
onProgress(`Removing skill-scanner via ${m.via}…`);
|
|
334
|
+
try {
|
|
335
|
+
await execFileAsync(m.cmd, m.argv, { timeout: 120000, maxBuffer: 32 * 1024 * 1024 });
|
|
336
|
+
attempts.push(`${m.via}:0`);
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
const err = e;
|
|
340
|
+
attempts.push(`${m.via}:${err.code ?? "err"}`);
|
|
341
|
+
}
|
|
342
|
+
if (!SkillScannerInstaller.onPath()) {
|
|
343
|
+
return { ok: true, message: `removed via ${m.via}`, via: m.via };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
ok: false,
|
|
348
|
+
message: `skill-scanner is still on PATH after uninstall attempts (${attempts.join(", ")}). ` +
|
|
349
|
+
"It may have been installed by another tool; remove it manually.",
|
|
350
|
+
via: "",
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/** Severity tiers, low→high, used to escalate a report's severity by deep
|
|
355
|
+
* findings. Mirrors the order used by skill review. */
|
|
356
|
+
const _TIER_ORDER = ["clean", "low", "medium", "high", "critical"];
|
|
357
|
+
/**
|
|
358
|
+
* The highest **actionable** tier (medium/high/critical) among a deep result's
|
|
359
|
+
* findings, or "clean". low/INFO findings are reported but never escalate the
|
|
360
|
+
* overall severity / exit code — matching the quick-scan contract.
|
|
361
|
+
*/
|
|
362
|
+
export function deepSeverityTier(result) {
|
|
363
|
+
let tier = "clean";
|
|
364
|
+
for (const f of result.findings) {
|
|
365
|
+
if (FINDING_SEVERITIES.has(f.severity) && _TIER_ORDER.indexOf(f.severity) > _TIER_ORDER.indexOf(tier)) {
|
|
366
|
+
tier = f.severity;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return tier;
|
|
370
|
+
}
|
|
371
|
+
/** Count of actionable (medium+) deep findings. */
|
|
372
|
+
export function deepActionableCount(result) {
|
|
373
|
+
return result.findings.filter((f) => FINDING_SEVERITIES.has(f.severity)).length;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Resolve a usable SkillScanner for an opt-in --deep run, making it **easy**:
|
|
377
|
+
* if the engine isn't installed and we're on an interactive TTY (and not in
|
|
378
|
+
* --json mode), offer to install it in place. Returns a ready scanner, or null
|
|
379
|
+
* when it's unavailable and the caller should print the install hint + exit 2.
|
|
380
|
+
*/
|
|
381
|
+
export async function ensureSkillScanner(opts = {}) {
|
|
382
|
+
let scanner = new SkillScanner();
|
|
383
|
+
if (scanner.isAvailable())
|
|
384
|
+
return scanner;
|
|
385
|
+
const interactive = !!process.stdin.isTTY && !opts.json;
|
|
386
|
+
if (interactive) {
|
|
387
|
+
process.stderr.write("\nThe --deep engine (skill-scanner) is not installed.\n");
|
|
388
|
+
const yes = await askYesNo("Install it now? (heavy third-party package, isolated via uv/pip)", false);
|
|
389
|
+
if (yes) {
|
|
390
|
+
const result = await new SkillScannerInstaller().install(SKILL_SCANNER_VERSION, (m) => process.stderr.write(` ${m}\n`));
|
|
391
|
+
if (result.ok) {
|
|
392
|
+
scanner = new SkillScanner();
|
|
393
|
+
if (scanner.isAvailable()) {
|
|
394
|
+
process.stderr.write(`skill-scanner installed (${result.via}).\n`);
|
|
395
|
+
return scanner;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
process.stderr.write(`Install failed: ${result.message}\n`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
package/dist/utils/api.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConfigManager } from "../core/config-manager.js";
|
|
1
2
|
export const API = "https://rafter.so/api/";
|
|
2
3
|
// Exit codes
|
|
3
4
|
export const EXIT_SUCCESS = 0;
|
|
@@ -38,7 +39,19 @@ export function resolveKey(cliKey) {
|
|
|
38
39
|
return cliKey;
|
|
39
40
|
if (process.env.RAFTER_API_KEY)
|
|
40
41
|
return process.env.RAFTER_API_KEY;
|
|
41
|
-
|
|
42
|
+
// Lowest precedence: a key persisted in the GLOBAL ~/.rafter/config.json via
|
|
43
|
+
// `rafter agent config set backend.apiKey`. Read through load() (global only)
|
|
44
|
+
// — loadWithPolicy() never merges backend.*, so a project-local .rafter.yml
|
|
45
|
+
// can NOT inject a key that would redirect scans to another account.
|
|
46
|
+
try {
|
|
47
|
+
const stored = new ConfigManager().get("backend.apiKey");
|
|
48
|
+
if (typeof stored === "string" && stored.trim())
|
|
49
|
+
return stored.trim();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Config unreadable — fall through to the error below.
|
|
53
|
+
}
|
|
54
|
+
console.error("No API key provided. Use --api-key, set RAFTER_API_KEY, or run 'rafter agent config set backend.apiKey <key>'");
|
|
42
55
|
process.exit(EXIT_GENERAL_ERROR);
|
|
43
56
|
}
|
|
44
57
|
export function writePayload(data, fmt, quiet) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse unified git diff output and extract added/modified lines (+ side only).
|
|
3
|
+
* Dependency-free — expects `git diff -U0 --no-color` output (zero context lines).
|
|
4
|
+
*/
|
|
5
|
+
const HUNK_HEADER_RE = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
|
|
6
|
+
const NO_NEWLINE_RE = /^\$/;
|
|
7
|
+
/**
|
|
8
|
+
* Strip the `b/` prefix git adds to paths in `+++ b/path` headers.
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeDiffPath(raw) {
|
|
11
|
+
let p = raw.trim().replace(/\\/g, "/");
|
|
12
|
+
if (p.startsWith("b/"))
|
|
13
|
+
p = p.slice(2);
|
|
14
|
+
else if (p.startsWith("a/"))
|
|
15
|
+
p = p.slice(2);
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Extract added lines from a unified diff patch. Context lines (leading space)
|
|
20
|
+
* and deletions (leading '-') are ignored. Modifications appear as `-` then `+`;
|
|
21
|
+
* only the `+` side is returned.
|
|
22
|
+
*/
|
|
23
|
+
export function parseUnifiedDiffAddedLines(patch) {
|
|
24
|
+
const results = [];
|
|
25
|
+
let currentFile = null;
|
|
26
|
+
let newLine = 0;
|
|
27
|
+
for (const rawLine of patch.split(/\r?\n/)) {
|
|
28
|
+
if (NO_NEWLINE_RE.test(rawLine))
|
|
29
|
+
continue;
|
|
30
|
+
if (rawLine.startsWith("diff --git ")) {
|
|
31
|
+
currentFile = null;
|
|
32
|
+
newLine = 0;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (rawLine.startsWith("Binary files ") && rawLine.endsWith(" differ")) {
|
|
36
|
+
currentFile = null;
|
|
37
|
+
newLine = 0;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// `+++ `/`--- ` are file headers ONLY in the file-header region (before the
|
|
41
|
+
// first `@@`, where newLine is still 0). Inside a hunk body (newLine > 0) a
|
|
42
|
+
// line like `++ x` serializes as `+++ x` and is ADDED CONTENT, not a header
|
|
43
|
+
// — guarding on newLine keeps it from corrupting currentFile.
|
|
44
|
+
if (newLine <= 0 && rawLine.startsWith("+++ ")) {
|
|
45
|
+
const pathPart = rawLine.slice(4).trim();
|
|
46
|
+
if (pathPart === "/dev/null") {
|
|
47
|
+
currentFile = null;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
currentFile = normalizeDiffPath(pathPart);
|
|
51
|
+
}
|
|
52
|
+
newLine = 0;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (newLine <= 0 && rawLine.startsWith("--- ")) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const hunk = HUNK_HEADER_RE.exec(rawLine);
|
|
59
|
+
if (hunk) {
|
|
60
|
+
newLine = parseInt(hunk[1], 10);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!currentFile || newLine <= 0)
|
|
64
|
+
continue;
|
|
65
|
+
// Any '+' line here is added content (real headers were consumed above
|
|
66
|
+
// while newLine <= 0). Do NOT exclude '+++...': an added line whose content
|
|
67
|
+
// starts with '++' would otherwise be dropped, missing a secret.
|
|
68
|
+
if (rawLine.startsWith("+")) {
|
|
69
|
+
results.push({
|
|
70
|
+
file: currentFile,
|
|
71
|
+
line: newLine,
|
|
72
|
+
text: rawLine.slice(1),
|
|
73
|
+
});
|
|
74
|
+
newLine++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (rawLine.startsWith("-")) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (rawLine.startsWith(" ")) {
|
|
81
|
+
newLine++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rafter-security/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
34
|
-
"axios": "^1.
|
|
34
|
+
"axios": "^1.16.0",
|
|
35
35
|
"chalk": "^5.3.0",
|
|
36
36
|
"chokidar": "^5.0.0",
|
|
37
37
|
"commander": "^11.1.0",
|
|
38
38
|
"dotenv": "^16.4.5",
|
|
39
|
-
"js-yaml": "^4.
|
|
39
|
+
"js-yaml": "^4.2.0",
|
|
40
40
|
"minimatch": "^10.2.4",
|
|
41
41
|
"ora": "^7.0.1",
|
|
42
|
-
"tar": "^7.5.
|
|
42
|
+
"tar": "^7.5.16"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: rafter-security
|
|
3
3
|
description: Security toolkit for AI workflows. Use when scanning code or repos for vulnerabilities, auditing third-party skills/MCPs/agent configs before installing, evaluating shell commands before running them, or generating secure design questions for new features. Provides `rafter run` (remote SAST + SCA, needs RAFTER_API_KEY), `rafter secrets` (offline secrets-only), `rafter agent exec --dry-run` (command-risk classification), and `rafter skill review`.
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.10
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|