@rafter-security/cli 0.11.1 → 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/scan.js +46 -3
- package/dist/commands/ci/init.js +4 -1
- package/dist/commands/hook/posttool.js +11 -0
- package/dist/scanners/secret-patterns.js +7 -2
- package/package.json +1 -1
- package/resources/rafter-security-skill.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
|
}
|
|
@@ -326,6 +326,10 @@ function outputScanResults(results, opts, context, exitOnFindings = true, suppre
|
|
|
326
326
|
// Exit code: findings dominate (1); otherwise an unreadable file is a scan
|
|
327
327
|
// that could not complete cleanly (2); a clean, complete scan is 0.
|
|
328
328
|
const scanExitCode = keptResults.length > 0 ? 1 : readErrors.length > 0 ? 2 : 0;
|
|
329
|
+
// Before the format branches, so --json and SARIF runs are recorded too. A
|
|
330
|
+
// clean scan is recorded as well: "we looked on this date and found nothing"
|
|
331
|
+
// is what a postmortem needs.
|
|
332
|
+
logScanToAudit(keptResults, context);
|
|
329
333
|
if (format === "sarif") {
|
|
330
334
|
outputSarif(keptResults, scanExitCode);
|
|
331
335
|
return;
|
|
@@ -592,7 +596,7 @@ function diffModeReport(opts) {
|
|
|
592
596
|
* scanning. The caller resolves this from `--no-auto-update` and the
|
|
593
597
|
* `scan.auto_update_betterleaks` config key.
|
|
594
598
|
*/
|
|
595
|
-
async function selectEngine(preference, quiet, autoUpdate = true) {
|
|
599
|
+
export async function selectEngine(preference, quiet, autoUpdate = true) {
|
|
596
600
|
if (preference === "patterns") {
|
|
597
601
|
return { engine: "patterns", reason: null };
|
|
598
602
|
}
|
|
@@ -682,7 +686,7 @@ export function autoUpdateEnabled(opts, scanCfg) {
|
|
|
682
686
|
/**
|
|
683
687
|
* Scan a file with selected engine
|
|
684
688
|
*/
|
|
685
|
-
async function scanFile(filePath, engine, scanCfg, report) {
|
|
689
|
+
export async function scanFile(filePath, engine, scanCfg, report) {
|
|
686
690
|
const runPatterns = () => {
|
|
687
691
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
688
692
|
const result = scanner.scanFile(filePath);
|
|
@@ -729,7 +733,7 @@ function errorText(e) {
|
|
|
729
733
|
/**
|
|
730
734
|
* Scan a directory with selected engine
|
|
731
735
|
*/
|
|
732
|
-
async function scanDirectory(dirPath, engine, scanCfg, history, respectGitignore, report) {
|
|
736
|
+
export async function scanDirectory(dirPath, engine, scanCfg, history, respectGitignore, report) {
|
|
733
737
|
// respectGitignore default is true. Both engines honor it: the patterns
|
|
734
738
|
// engine via RegexScanner.scanDirectory, betterleaks by scanning only the
|
|
735
739
|
// files git does not ignore (BetterleaksScanner.scanDirectory, #262).
|
|
@@ -884,6 +888,45 @@ async function watchAndScan(watchPath, opts, scanCfg, suppressions = []) {
|
|
|
884
888
|
});
|
|
885
889
|
});
|
|
886
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
* Record that a scan ran, so `rafter agent audit` has something in it.
|
|
893
|
+
*
|
|
894
|
+
* `rafter secrets` told the user "Run 'rafter agent audit' to see the security
|
|
895
|
+
* log" and the log was always empty, because only command interception ever
|
|
896
|
+
* wrote to it — three of seven beta users followed that hint and hit a dead
|
|
897
|
+
* end, one of them immediately after a correct and useful scan result. The
|
|
898
|
+
* first thing a careful person does with a security finding is look for the
|
|
899
|
+
* record of it.
|
|
900
|
+
*
|
|
901
|
+
* Counts and pattern NAMES only — never a matched value, not even redacted.
|
|
902
|
+
* The audit log is a postmortem artifact that outlives the terminal, so it
|
|
903
|
+
* must not become a second place secrets live.
|
|
904
|
+
*/
|
|
905
|
+
function logScanToAudit(results, context) {
|
|
906
|
+
try {
|
|
907
|
+
const totalMatches = results.reduce((n, r) => n + r.matches.length, 0);
|
|
908
|
+
const patterns = [...new Set(results.flatMap((r) => r.matches.map((m) => m.pattern.name)))].sort();
|
|
909
|
+
new AuditLogger().log({
|
|
910
|
+
eventType: "scan_executed",
|
|
911
|
+
securityCheck: {
|
|
912
|
+
passed: totalMatches === 0,
|
|
913
|
+
reason: totalMatches === 0
|
|
914
|
+
? "Secret scan completed with no findings"
|
|
915
|
+
: `Secret scan found ${totalMatches} secret(s) in ${results.length} file(s)`,
|
|
916
|
+
details: {
|
|
917
|
+
filesWithFindings: results.length,
|
|
918
|
+
totalMatches,
|
|
919
|
+
patterns,
|
|
920
|
+
...(context ? { context } : {}),
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
resolution: { actionTaken: totalMatches === 0 ? "allowed" : "blocked" },
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
catch {
|
|
927
|
+
// Never let audit logging break a scan — the scan result is the product.
|
|
928
|
+
}
|
|
929
|
+
}
|
|
887
930
|
/**
|
|
888
931
|
* Log watch findings to audit log
|
|
889
932
|
*/
|
package/dist/commands/ci/init.js
CHANGED
|
@@ -22,7 +22,10 @@ export function createCiInitCommand() {
|
|
|
22
22
|
console.error(`Valid options: ${validPlatforms.join(", ")}`);
|
|
23
23
|
process.exit(1);
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
// commander stores `--with-remote` as `opts.withRemote`; `--with-backend`
|
|
26
|
+
// is the deprecated alias. Reading a non-existent `opts.includeRemote`
|
|
27
|
+
// meant `--with-remote` silently dropped the security-audit job (sable-o7vh).
|
|
28
|
+
const includeRemote = !!(opts.withRemote || opts.withBackend);
|
|
26
29
|
const { content, defaultPath } = generateTemplate(platform, includeRemote);
|
|
27
30
|
const outputPath = opts.output || defaultPath;
|
|
28
31
|
const outputDir = path.dirname(outputPath);
|
|
@@ -97,6 +97,14 @@ function evaluateToolResponse(payload) {
|
|
|
97
97
|
modified = true;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
// Scan and redact the error field (sable-t578). A tool that fails and echoes
|
|
101
|
+
// a credential in its error text surfaces it to the user just like output.
|
|
102
|
+
if (typeof tool_response.error === "string" && tool_response.error) {
|
|
103
|
+
if (scanner.hasSecrets(tool_response.error)) {
|
|
104
|
+
redacted.error = scanner.redact(tool_response.error);
|
|
105
|
+
modified = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
100
108
|
if (modified) {
|
|
101
109
|
const audit = new AuditLogger();
|
|
102
110
|
const matchCount = countMatches(scanner, tool_response);
|
|
@@ -113,6 +121,9 @@ function countMatches(scanner, tool_response) {
|
|
|
113
121
|
if (typeof tool_response?.content === "string" && tool_response.content) {
|
|
114
122
|
count += scanner.scanText(tool_response.content).length;
|
|
115
123
|
}
|
|
124
|
+
if (typeof tool_response?.error === "string" && tool_response.error) {
|
|
125
|
+
count += scanner.scanText(tool_response.error).length;
|
|
126
|
+
}
|
|
116
127
|
return count;
|
|
117
128
|
}
|
|
118
129
|
// Bound the stdin read so a hung/never-closing stdin can't wedge the hook.
|
|
@@ -8,7 +8,7 @@ export const DEFAULT_SECRET_PATTERNS = [
|
|
|
8
8
|
name: "AWS Access Key ID",
|
|
9
9
|
// Negative lookahead excludes the canonical AWS-docs example key
|
|
10
10
|
// (AKIAIOSFODNN7EXAMPLE and its siblings, which all end in EXAMPLE).
|
|
11
|
-
// betterleaks skips these too (
|
|
11
|
+
// betterleaks skips these too (#230); matching that keeps the two
|
|
12
12
|
// engines from disagreeing on a well-known public non-secret.
|
|
13
13
|
regex: "(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)(?![A-Z0-9]{9}EXAMPLE)[A-Z0-9]{16}",
|
|
14
14
|
severity: "critical",
|
|
@@ -16,7 +16,12 @@ export const DEFAULT_SECRET_PATTERNS = [
|
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
name: "AWS Secret Access Key",
|
|
19
|
-
|
|
19
|
+
// Negative lookahead excludes the canonical AWS-docs example secret key
|
|
20
|
+
// (wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY, which ends in EXAMPLEKEY).
|
|
21
|
+
// betterleaks skips this too (#230); matching that keeps the two
|
|
22
|
+
// engines from disagreeing on a well-known public non-secret, mirroring
|
|
23
|
+
// the AWS Access Key ID exemption above.
|
|
24
|
+
regex: "(?i)aws(.{0,20})?['\"]?(?![0-9a-zA-Z/+]{30}EXAMPLEKEY)[0-9a-zA-Z/+]{40}['\"]?",
|
|
20
25
|
severity: "critical",
|
|
21
26
|
description: "AWS Secret Access Key detected"
|
|
22
27
|
},
|
package/package.json
CHANGED
|
@@ -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.11.
|
|
4
|
+
version: 0.11.2
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|