@rafter-security/cli 0.10.5 → 0.11.1
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/exec.js +26 -9
- package/dist/commands/agent/init.js +286 -225
- package/dist/commands/agent/install-hook.js +19 -8
- package/dist/commands/agent/scan.js +270 -70
- package/dist/commands/agent/status.js +2 -2
- 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/run.js +25 -2
- package/dist/commands/backend/scan-status.js +34 -4
- 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 +7 -1
- 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 +5 -1
- package/dist/scanners/union.js +31 -19
- package/dist/utils/api.js +35 -1
- package/dist/utils/env-guard.js +14 -14
- package/dist/utils/git-diff.js +36 -20
- package/dist/utils/git.js +164 -52
- 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
|
@@ -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() {
|