@rafter-security/cli 0.8.1 → 0.8.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.
|
@@ -49,6 +49,7 @@ export function createScanCommand() {
|
|
|
49
49
|
.option("--baseline", "Filter findings present in the saved baseline")
|
|
50
50
|
.option("--watch", "Watch for file changes and re-scan on change")
|
|
51
51
|
.option("--history", "Scan git history for secrets (requires betterleaks engine)")
|
|
52
|
+
.option("--no-gitignore", "Scan files even if .gitignore would exclude them (default: respect .gitignore)")
|
|
52
53
|
.action(async (scanPath, opts) => {
|
|
53
54
|
// Validate flags before doing any work.
|
|
54
55
|
const validEngines = ["auto", "betterleaks", "patterns"];
|
|
@@ -106,7 +107,7 @@ export function createScanCommand() {
|
|
|
106
107
|
if (!opts.quiet) {
|
|
107
108
|
console.error(`Scanning directory: ${resolvedPath} (${engine})`);
|
|
108
109
|
}
|
|
109
|
-
results = await scanDirectory(resolvedPath, engine, scanCfg, opts.history);
|
|
110
|
+
results = await scanDirectory(resolvedPath, engine, scanCfg, opts.history, opts.gitignore);
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
112
113
|
if (!opts.quiet) {
|
|
@@ -413,7 +414,10 @@ async function scanFile(filePath, engine, scanCfg) {
|
|
|
413
414
|
/**
|
|
414
415
|
* Scan a directory with selected engine
|
|
415
416
|
*/
|
|
416
|
-
async function scanDirectory(dirPath, engine, scanCfg, history) {
|
|
417
|
+
async function scanDirectory(dirPath, engine, scanCfg, history, respectGitignore) {
|
|
418
|
+
// respectGitignore default is true. The patterns engine honors it via
|
|
419
|
+
// RegexScanner.scanDirectory; betterleaks honors it natively (gitleaks
|
|
420
|
+
// ancestry — reads .gitignore unless --no-git is set).
|
|
417
421
|
if (engine === "betterleaks") {
|
|
418
422
|
try {
|
|
419
423
|
const bl = new BetterleaksScanner();
|
|
@@ -422,12 +426,18 @@ async function scanDirectory(dirPath, engine, scanCfg, history) {
|
|
|
422
426
|
catch (e) {
|
|
423
427
|
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
424
428
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
425
|
-
return scanner.scanDirectory(dirPath, {
|
|
429
|
+
return scanner.scanDirectory(dirPath, {
|
|
430
|
+
excludePaths: scanCfg?.excludePaths,
|
|
431
|
+
respectGitignore,
|
|
432
|
+
});
|
|
426
433
|
}
|
|
427
434
|
}
|
|
428
435
|
else {
|
|
429
436
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
430
|
-
return scanner.scanDirectory(dirPath, {
|
|
437
|
+
return scanner.scanDirectory(dirPath, {
|
|
438
|
+
excludePaths: scanCfg?.excludePaths,
|
|
439
|
+
respectGitignore,
|
|
440
|
+
});
|
|
431
441
|
}
|
|
432
442
|
}
|
|
433
443
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawnSync } from "child_process";
|
|
1
2
|
import fs from "fs";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import { PatternEngine } from "../core/pattern-engine.js";
|
|
@@ -80,7 +81,10 @@ export class RegexScanner {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
const files = this.walkDirectory(dirPath, exclude, options?.maxDepth || 10);
|
|
83
|
-
|
|
84
|
+
const filtered = options?.respectGitignore === false
|
|
85
|
+
? files
|
|
86
|
+
: filterGitIgnored(files, dirPath);
|
|
87
|
+
return this.scanFiles(filtered);
|
|
84
88
|
}
|
|
85
89
|
/**
|
|
86
90
|
* Scan text content directly
|
|
@@ -153,3 +157,65 @@ export class RegexScanner {
|
|
|
153
157
|
return binaryExtensions.includes(ext);
|
|
154
158
|
}
|
|
155
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Filter out files that git would ignore relative to `scanRoot`.
|
|
162
|
+
*
|
|
163
|
+
* Uses `git check-ignore --stdin --no-index` inside the scan root's work
|
|
164
|
+
* tree so every gitignore semantic git itself supports (nested .gitignores,
|
|
165
|
+
* negations, .git/info/exclude, the configured global excludes file, the
|
|
166
|
+
* `gitignore` pattern grammar) is honored exactly. Zero new dependencies —
|
|
167
|
+
* if git isn't installed or the scan root sits outside a work tree, returns
|
|
168
|
+
* the input unchanged.
|
|
169
|
+
*
|
|
170
|
+
* Batched: all candidate paths are piped through one subprocess.
|
|
171
|
+
*/
|
|
172
|
+
function filterGitIgnored(files, scanRoot) {
|
|
173
|
+
if (files.length === 0)
|
|
174
|
+
return files;
|
|
175
|
+
// Locate the git work tree that owns scanRoot. Bail out (no filter) if
|
|
176
|
+
// scanRoot is outside a repo or git is missing — the user's `rafter
|
|
177
|
+
// secrets <dir>` invocation against a non-repo should not error.
|
|
178
|
+
const probe = spawnSync("git", ["-C", scanRoot, "rev-parse", "--show-toplevel"], {
|
|
179
|
+
encoding: "utf-8",
|
|
180
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
181
|
+
timeout: 5000,
|
|
182
|
+
});
|
|
183
|
+
if (probe.status !== 0)
|
|
184
|
+
return files;
|
|
185
|
+
const workTree = probe.stdout.trim();
|
|
186
|
+
if (!workTree)
|
|
187
|
+
return files;
|
|
188
|
+
// Send the candidate file list to `git check-ignore --stdin`. It echoes
|
|
189
|
+
// back (on stdout) only the paths that match a gitignore rule. Use null
|
|
190
|
+
// delimiters (`-z`) on input and output so paths with spaces, newlines, or
|
|
191
|
+
// any other shell metacharacter survive intact. `--no-index` makes git
|
|
192
|
+
// evaluate rules without consulting the index (so an untracked file in a
|
|
193
|
+
// freshly-cloned repo is still classified).
|
|
194
|
+
//
|
|
195
|
+
// The paths in `files` are absolute. `git check-ignore` accepts paths
|
|
196
|
+
// relative to the work tree OR absolute paths within it; we pass through
|
|
197
|
+
// unchanged.
|
|
198
|
+
const stdin = files.join("\0") + "\0";
|
|
199
|
+
const result = spawnSync("git", ["-C", workTree, "check-ignore", "--stdin", "--no-index", "-z"], {
|
|
200
|
+
input: stdin,
|
|
201
|
+
encoding: "utf-8",
|
|
202
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
203
|
+
timeout: 30000,
|
|
204
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
205
|
+
});
|
|
206
|
+
// Exit codes: 0 = at least one path matched; 1 = no paths matched;
|
|
207
|
+
// 128 = error (corrupt repo, bad flag, etc.). Treat 128 as "no filter" so
|
|
208
|
+
// a broken environment doesn't break a scan.
|
|
209
|
+
if (result.status !== 0 && result.status !== 1)
|
|
210
|
+
return files;
|
|
211
|
+
const ignored = new Set();
|
|
212
|
+
if (result.stdout) {
|
|
213
|
+
for (const p of result.stdout.split("\0")) {
|
|
214
|
+
if (p)
|
|
215
|
+
ignored.add(p);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (ignored.size === 0)
|
|
219
|
+
return files;
|
|
220
|
+
return files.filter((f) => !ignored.has(f));
|
|
221
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rafter-security/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/Raftersecurity/rafter-cli.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://rafter.so",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Raftersecurity/rafter-cli/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Rafter Security",
|
|
15
|
+
"description": "Rafter CLI — the default security agent for AI coding workflows. Free for individuals and open source.",
|
|
5
16
|
"bin": {
|
|
6
17
|
"rafter": "./dist/index.js"
|
|
7
18
|
},
|
|
@@ -18,7 +29,6 @@
|
|
|
18
29
|
"engines": {
|
|
19
30
|
"node": ">=18"
|
|
20
31
|
},
|
|
21
|
-
"license": "MIT",
|
|
22
32
|
"dependencies": {
|
|
23
33
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
24
34
|
"axios": "^1.13.5",
|
|
@@ -38,4 +48,4 @@
|
|
|
38
48
|
"typescript": "^5.4.5",
|
|
39
49
|
"vitest": "^4.1.0"
|
|
40
50
|
}
|
|
41
|
-
}
|
|
51
|
+
}
|
|
@@ -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.2
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|