@rafter-security/cli 0.10.6 → 0.11.2
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/baseline.js +9 -50
- package/dist/commands/agent/components.js +7 -2
- package/dist/commands/agent/exec.js +26 -9
- package/dist/commands/agent/init.js +275 -220
- package/dist/commands/agent/install-hook.js +17 -6
- package/dist/commands/agent/scan.js +309 -71
- package/dist/commands/agent/update-skill-scanner.js +1 -1
- package/dist/commands/agent/verify.js +39 -15
- package/dist/commands/backend/get.js +6 -2
- package/dist/commands/backend/scan-status.js +34 -4
- package/dist/commands/ci/init.js +4 -1
- package/dist/commands/hook/posttool.js +11 -0
- package/dist/commands/hook/pretool.js +124 -36
- package/dist/commands/mcp/server.js +184 -129
- package/dist/commands/report.js +6 -2
- package/dist/core/audit-logger.js +47 -17
- package/dist/core/config-manager.js +46 -8
- package/dist/core/custom-patterns.js +28 -8
- package/dist/core/docs-loader.js +33 -3
- package/dist/core/pattern-engine.js +23 -5
- package/dist/core/policy-loader.js +15 -4
- package/dist/core/risk-rules.js +391 -9
- package/dist/index.js +6 -0
- package/dist/scanners/betterleaks.js +127 -14
- package/dist/scanners/git-history-scan.js +75 -0
- package/dist/scanners/regex-scanner.js +16 -2
- package/dist/scanners/secret-patterns.js +11 -2
- package/dist/scanners/union.js +31 -19
- package/dist/utils/api.js +35 -1
- package/dist/utils/git-diff.js +36 -20
- package/dist/utils/skill-manager.js +4 -3
- package/package.json +16 -15
- package/resources/continue-rules/rafter.md +1 -1
- package/resources/cursor-rules/rafter.mdc +1 -1
- package/resources/rafter-security-skill.md +3 -1
- package/resources/skills/rafter/SKILL.md +1 -2
- package/resources/skills/rafter/docs/guardrails.md +1 -1
- package/resources/skills/rafter-code-review/SKILL.md +0 -1
- package/resources/skills/rafter-secure-design/SKILL.md +0 -1
- package/resources/skills/rafter-skill-review/SKILL.md +0 -1
- package/resources/windsurf-rules/rafter.md +1 -1
|
@@ -3,9 +3,8 @@ import fs from "fs";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fmt } from "../../utils/formatter.js";
|
|
6
|
-
import { RegexScanner } from "../../scanners/regex-scanner.js";
|
|
7
|
-
import { BetterleaksScanner } from "../../scanners/betterleaks.js";
|
|
8
6
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
7
|
+
import { selectEngine, scanFile, scanDirectory } from "./scan.js";
|
|
9
8
|
const BASELINE_PATH = path.join(os.homedir(), ".rafter", "baseline.json");
|
|
10
9
|
function loadBaseline() {
|
|
11
10
|
if (!fs.existsSync(BASELINE_PATH)) {
|
|
@@ -55,13 +54,19 @@ function createBaselineCreateCommand() {
|
|
|
55
54
|
const cfg = manager.loadWithPolicy();
|
|
56
55
|
const scanCfg = cfg.agent?.scan;
|
|
57
56
|
console.error(`Scanning ${resolvedPath} to build baseline...`);
|
|
58
|
-
|
|
57
|
+
// Use the same engine selection and union the scan command uses, so the
|
|
58
|
+
// baseline captures exactly what a later `rafter secrets` would find
|
|
59
|
+
// (sable-qb9g). In `auto` this runs BOTH engines and unions; the old
|
|
60
|
+
// local helpers ran betterleaks-only, so a secret only the patterns
|
|
61
|
+
// engine catches never made it into the baseline.
|
|
62
|
+
const autoUpdate = scanCfg?.autoUpdateBetterleaks !== false;
|
|
63
|
+
const { engine } = await selectEngine(opts.engine || "auto", false, autoUpdate);
|
|
59
64
|
let results;
|
|
60
65
|
if (fs.statSync(resolvedPath).isDirectory()) {
|
|
61
66
|
results = await scanDirectory(resolvedPath, engine, scanCfg);
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
|
-
results = await scanFile(resolvedPath, engine);
|
|
69
|
+
results = await scanFile(resolvedPath, engine, scanCfg);
|
|
65
70
|
}
|
|
66
71
|
const now = new Date().toISOString();
|
|
67
72
|
const entries = [];
|
|
@@ -165,49 +170,3 @@ function createBaselineAddCommand() {
|
|
|
165
170
|
console.log(fmt.success(`Added to baseline: ${opts.pattern} in ${opts.file}`));
|
|
166
171
|
});
|
|
167
172
|
}
|
|
168
|
-
// ── helpers ─────────────────────────────────────────────────────────
|
|
169
|
-
async function selectEngine(preference) {
|
|
170
|
-
if (preference === "patterns")
|
|
171
|
-
return "patterns";
|
|
172
|
-
if (preference === "betterleaks") {
|
|
173
|
-
const b = new BetterleaksScanner();
|
|
174
|
-
return (await b.isAvailable()) ? "betterleaks" : "patterns";
|
|
175
|
-
}
|
|
176
|
-
if (preference !== "auto") {
|
|
177
|
-
console.error(`Invalid engine: ${preference}. Valid values: auto, betterleaks, patterns`);
|
|
178
|
-
process.exit(2);
|
|
179
|
-
}
|
|
180
|
-
const b = new BetterleaksScanner();
|
|
181
|
-
return (await b.isAvailable()) ? "betterleaks" : "patterns";
|
|
182
|
-
}
|
|
183
|
-
async function scanFile(filePath, engine) {
|
|
184
|
-
if (engine === "betterleaks") {
|
|
185
|
-
try {
|
|
186
|
-
const b = new BetterleaksScanner();
|
|
187
|
-
const r = await b.scanFile(filePath);
|
|
188
|
-
return r.matches.length > 0 ? [r] : [];
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
const s = new RegexScanner();
|
|
192
|
-
const r = s.scanFile(filePath);
|
|
193
|
-
return r.matches.length > 0 ? [r] : [];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const s = new RegexScanner();
|
|
197
|
-
const r = s.scanFile(filePath);
|
|
198
|
-
return r.matches.length > 0 ? [r] : [];
|
|
199
|
-
}
|
|
200
|
-
async function scanDirectory(dirPath, engine, scanCfg) {
|
|
201
|
-
if (engine === "betterleaks") {
|
|
202
|
-
try {
|
|
203
|
-
const b = new BetterleaksScanner();
|
|
204
|
-
return await b.scanDirectory(dirPath);
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
const s = new RegexScanner();
|
|
208
|
-
return s.scanDirectory(dirPath, { excludePaths: scanCfg?.excludePaths });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const s = new RegexScanner();
|
|
212
|
-
return s.scanDirectory(dirPath, { excludePaths: scanCfg?.excludePaths });
|
|
213
|
-
}
|
|
@@ -981,9 +981,14 @@ function aiderRead() {
|
|
|
981
981
|
fs.writeFileSync(configPath, yaml.dump(parsed), "utf-8");
|
|
982
982
|
},
|
|
983
983
|
uninstall: () => {
|
|
984
|
-
|
|
984
|
+
// Excise only the managed block; any user content in RAFTER.md survives.
|
|
985
|
+
// If the file was ours alone (nothing but the block), remove it.
|
|
986
|
+
// A RAFTER.md with no markers is user-authored — leave it untouched.
|
|
987
|
+
if (fs.existsSync(rafterMdPath) && stripMarkerBlock(rafterMdPath)) {
|
|
985
988
|
try {
|
|
986
|
-
fs.
|
|
989
|
+
if (fs.readFileSync(rafterMdPath, "utf-8").trim() === "") {
|
|
990
|
+
fs.rmSync(rafterMdPath, { force: true });
|
|
991
|
+
}
|
|
987
992
|
}
|
|
988
993
|
catch { /* best-effort */ }
|
|
989
994
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command, Option } from "commander";
|
|
2
2
|
import { CommandInterceptor } from "../../core/command-interceptor.js";
|
|
3
3
|
import { scanAddedDiffLines } from "../../scanners/git-diff-scan.js";
|
|
4
|
-
import { parseUnifiedDiffAddedLines } from "../../utils/git-diff.js";
|
|
4
|
+
import { parseUnifiedDiffAddedLines, gitDiffMaxBuffer } from "../../utils/git-diff.js";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
6
|
import readline from "readline";
|
|
7
7
|
import { fmt } from "../../utils/formatter.js";
|
|
@@ -56,6 +56,11 @@ export function createExecCommand() {
|
|
|
56
56
|
// Step 3: Pre-execution scanning for git commands
|
|
57
57
|
if (!opts.skipScan && isGitCommand(command)) {
|
|
58
58
|
const scanResult = await scanStagedFiles();
|
|
59
|
+
if (scanResult.scanError) {
|
|
60
|
+
console.error(`Error: secret scan could not run (${scanResult.scanError}); command blocked`);
|
|
61
|
+
interceptor.logEvaluation(evaluation, "blocked");
|
|
62
|
+
process.exit(2);
|
|
63
|
+
}
|
|
59
64
|
if (scanResult.secretsFound) {
|
|
60
65
|
console.error(`\n${fmt.warning("Secrets detected in staged files!")}\n`);
|
|
61
66
|
console.error(`Found ${scanResult.count} secret(s) in ${scanResult.files} file(s)`);
|
|
@@ -120,7 +125,7 @@ export function joinCommandParts(parts) {
|
|
|
120
125
|
return parts[0];
|
|
121
126
|
return parts.map(shellQuote).join(" ");
|
|
122
127
|
}
|
|
123
|
-
function shellQuote(token) {
|
|
128
|
+
export function shellQuote(token) {
|
|
124
129
|
if (token === "")
|
|
125
130
|
return "''";
|
|
126
131
|
if (/^[A-Za-z0-9_\/:=@.,+%-]+$/.test(token))
|
|
@@ -132,18 +137,27 @@ function isGitCommand(command) {
|
|
|
132
137
|
command.trim().startsWith("git push");
|
|
133
138
|
}
|
|
134
139
|
async function scanStagedFiles() {
|
|
140
|
+
let repoRoot;
|
|
141
|
+
try {
|
|
142
|
+
repoRoot = execSync("git rev-parse --show-toplevel", {
|
|
143
|
+
encoding: "utf-8",
|
|
144
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
145
|
+
}).trim();
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// Not a git repo: no staged files to scan.
|
|
149
|
+
return { secretsFound: false, count: 0, files: 0 };
|
|
150
|
+
}
|
|
135
151
|
try {
|
|
136
152
|
const patch = execSync("git diff -U0 --no-color --cached --diff-filter=ACM", {
|
|
137
153
|
encoding: "utf-8",
|
|
138
154
|
stdio: ["pipe", "pipe", "ignore"],
|
|
155
|
+
// At the default 1 MiB buffer a large commit skipped the scan silently (#274).
|
|
156
|
+
maxBuffer: gitDiffMaxBuffer(),
|
|
139
157
|
}).trim();
|
|
140
158
|
if (!patch) {
|
|
141
159
|
return { secretsFound: false, count: 0, files: 0 };
|
|
142
160
|
}
|
|
143
|
-
const repoRoot = execSync("git rev-parse --show-toplevel", {
|
|
144
|
-
encoding: "utf-8",
|
|
145
|
-
stdio: ["pipe", "pipe", "ignore"],
|
|
146
|
-
}).trim();
|
|
147
161
|
const addedLines = parseUnifiedDiffAddedLines(patch);
|
|
148
162
|
if (addedLines.length === 0) {
|
|
149
163
|
return { secretsFound: false, count: 0, files: 0 };
|
|
@@ -156,9 +170,12 @@ async function scanStagedFiles() {
|
|
|
156
170
|
files: results.length,
|
|
157
171
|
};
|
|
158
172
|
}
|
|
159
|
-
catch {
|
|
160
|
-
//
|
|
161
|
-
|
|
173
|
+
catch (error) {
|
|
174
|
+
// Inside a repo, a scan that could not run must not read as "no secrets".
|
|
175
|
+
const scanError = error?.code === "ENOBUFS"
|
|
176
|
+
? "staged diff too large for the scanner to read"
|
|
177
|
+
: (error?.message ?? String(error));
|
|
178
|
+
return { secretsFound: false, count: 0, files: 0, scanError };
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
async function promptApproval() {
|