@rafter-security/cli 0.8.3 → 0.8.5

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.
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Merge findings from the betterleaks and patterns engines into one result
3
+ * set (sable-j85).
4
+ *
5
+ * `auto` mode now runs BOTH engines because each misses what the other
6
+ * catches: betterleaks 1.1.x does not detect AWS access keys (sable-h2y),
7
+ * while the regex patterns lack betterleaks's entropy/context heuristics.
8
+ * Running only one silently degrades coverage; the union restores it.
9
+ *
10
+ * Dedup: two findings are "the same secret" when they share
11
+ * `(file, line, column, matched-text)`. The key is deliberately conservative
12
+ * — it errs toward keeping both findings rather than collapsing two genuinely
13
+ * distinct secrets (e.g. the same token value pasted twice on one line at
14
+ * different columns), because dropping a real finding is a security
15
+ * regression for a scanner. The flip side: when the two engines extract
16
+ * slightly different text/columns for the same secret it is reported twice
17
+ * (once per engine) rather than merged — safe over-reporting, not a miss.
18
+ * When both engines DO agree on `(line, column, text)` we keep the betterleaks
19
+ * match — its `RuleID`-style `pattern.name` is the canonical id — and record
20
+ * both engines in `engines`. Ordering is deterministic: betterleaks findings
21
+ * first (in betterleaks's own order), then any patterns-only findings, grouped
22
+ * by the file each first appeared in.
23
+ */
24
+ export function unionScanResults(betterleaks, patterns) {
25
+ const fileOrder = [];
26
+ const byFile = new Map();
27
+ const ingest = (results, engine) => {
28
+ for (const r of results) {
29
+ let fileMap = byFile.get(r.file);
30
+ if (!fileMap) {
31
+ fileMap = new Map();
32
+ byFile.set(r.file, fileMap);
33
+ fileOrder.push(r.file);
34
+ }
35
+ for (const m of r.matches) {
36
+ // `line` and `column` are always digits (or "?"), so the first two
37
+ // spaces unambiguously delimit them from the matched secret — no key
38
+ // collisions even when the secret itself contains spaces. Column is
39
+ // part of the key so two distinct secrets sharing a line+text but
40
+ // sitting at different columns are NOT collapsed.
41
+ const key = `${m.line ?? "?"} ${m.column ?? "?"} ${m.match}`;
42
+ const existing = fileMap.get(key);
43
+ if (existing) {
44
+ if (!existing.engines.includes(engine))
45
+ existing.engines.push(engine);
46
+ }
47
+ else {
48
+ fileMap.set(key, { ...m, engines: [engine] });
49
+ }
50
+ }
51
+ }
52
+ };
53
+ ingest(betterleaks, "betterleaks");
54
+ ingest(patterns, "patterns");
55
+ return fileOrder.map((file) => ({
56
+ file,
57
+ matches: Array.from(byFile.get(file).values()),
58
+ }));
59
+ }
@@ -260,6 +260,26 @@ export class BinaryManager {
260
260
  return "unknown";
261
261
  }
262
262
  }
263
+ /**
264
+ * sable-o4k — detect a stale rafter-managed betterleaks binary. A leftover
265
+ * binary from an older rafter (a gitleaks-8.x install from before the rename,
266
+ * or an older betterleaks) runs `version` fine but emits a JSON report shape
267
+ * the current parser rejects, silently yielding zero findings on the default
268
+ * engine. We treat the managed binary as stale whenever its reported version
269
+ * doesn't contain the pinned BETTERLEAKS_VERSION rafter ships and parses
270
+ * against. PATH binaries are out of scope: we can't safely overwrite a
271
+ * user-managed install, and they may be a compatible different version.
272
+ * Read-only — never downloads.
273
+ */
274
+ async isManagedBetterleaksStale() {
275
+ if (!this.isBetterleaksInstalled())
276
+ return false;
277
+ const version = await this.getBetterleaksVersion();
278
+ // "unknown" (binary errored) / "not installed" — can't tell; don't churn.
279
+ if (version === "unknown" || version === "not installed")
280
+ return false;
281
+ return !version.includes(BETTERLEAKS_VERSION);
282
+ }
263
283
  /**
264
284
  * Get platform string for download URL
265
285
  */
@@ -0,0 +1,22 @@
1
+ import { createInterface } from "readline";
2
+ /**
3
+ * Ask a yes/no question on stderr (keeps stdout clean for JSON output) and
4
+ * resolve to a boolean. An empty answer resolves to `defaultYes`.
5
+ *
6
+ * Callers MUST gate this on `process.stdin.isTTY` — with no TTY the readline
7
+ * prompt has no interactive input and would hang waiting for a line.
8
+ */
9
+ export async function askYesNo(question, defaultYes = true) {
10
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
11
+ const suffix = defaultYes ? "[Y/n]" : "[y/N]";
12
+ return new Promise((resolve) => {
13
+ rl.question(` ${question} ${suffix} `, (answer) => {
14
+ rl.close();
15
+ const trimmed = answer.trim().toLowerCase();
16
+ if (trimmed === "")
17
+ resolve(defaultYes);
18
+ else
19
+ resolve(trimmed === "y" || trimmed === "yes");
20
+ });
21
+ });
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rafter-security/cli",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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.3
4
+ version: 0.8.5
5
5
  homepage: https://rafter.so
6
6
  metadata:
7
7
  openclaw:
@@ -55,8 +55,15 @@ If the finding is a leaked secret that was committed:
55
55
 
56
56
  Suppress only when the finding is a real false positive *for this context*, with a written reason. Two mechanisms:
57
57
 
58
- - **Inline**: `// rafter-ignore: HARDCODED_API_KEY — test fixture, not a real key`
59
- - **Baseline**: `rafter agent baseline` snapshots current findings; only *new* findings fail future scans. Good for adopting Rafter on a legacy codebase without a big bang.
58
+ - **`.rafter.yml`**: add an `ignore:` rule naming the path(s), the rule(s), and a `reason` (your evidence). Repo-tied; persists across scans:
59
+ ```yaml
60
+ ignore:
61
+ - paths: ["tests/fixtures/**", "src/legacy/config.py"]
62
+ rules: ["AWS Access Key ID"] # omit `rules` to suppress every finding on those paths
63
+ reason: "fake test keys — no live path"
64
+ ```
65
+ Match `rules` on the finding's **rule name** (case-insensitive), not a hashed `R-…` id. On a local `rafter scan`, suppressed findings move into a `_suppressed[]` array and don't affect the exit code — you only fail on a *non-suppressed* finding. Docs: https://docs.rafter.so/suppression
66
+ - **Baseline**: `rafter agent baseline create` snapshots current findings; scan with `rafter scan --baseline` so only *new* findings surface. Good for adopting Rafter on a legacy codebase without a big bang.
60
67
 
61
68
  Never suppress by:
62
69
  - Commenting out the rule globally.