@rafter-security/cli 0.8.6 → 0.8.7
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.
|
@@ -9,6 +9,7 @@ import { CommandInterceptor } from "../../core/command-interceptor.js";
|
|
|
9
9
|
import { AuditLogger } from "../../core/audit-logger.js";
|
|
10
10
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
11
11
|
import { listDocs, resolveDocSelector, fetchDoc } from "../../core/docs-loader.js";
|
|
12
|
+
import { writeSuppression } from "../../core/suppression-writer.js";
|
|
12
13
|
import { createRequire } from "module";
|
|
13
14
|
const _require = createRequire(import.meta.url);
|
|
14
15
|
const { version: CLI_VERSION } = _require("../../../package.json");
|
|
@@ -113,6 +114,23 @@ export function createServer() {
|
|
|
113
114
|
required: ["id_or_tag"],
|
|
114
115
|
},
|
|
115
116
|
},
|
|
117
|
+
{
|
|
118
|
+
name: "suppress_finding",
|
|
119
|
+
description: "Triage a false positive by persisting a suppression rule into the project's .rafter.yml. Use when a scan_secrets finding (or a remote scan finding) is a confirmed false positive — e.g. a test fixture or sample credential. Suppressed findings still surface under '_suppressed' in scan output, so the decision is reviewable and version-controlled. Always include a reason.",
|
|
120
|
+
inputSchema: {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
path: { type: "string", description: "File path or glob to suppress findings in (e.g. 'test/fixtures/**')" },
|
|
124
|
+
rules: {
|
|
125
|
+
type: "array",
|
|
126
|
+
items: { type: "string" },
|
|
127
|
+
description: "Specific rules to suppress, matched case-insensitively against a finding's rule name OR rule id — e.g. 'AWS Access Key' (local pattern name) or 'R-6D5E2' (remote SAST/SCA rule id). Omit to suppress all rules for the path. Honored by both local scans and remote `rafter run`.",
|
|
128
|
+
},
|
|
129
|
+
reason: { type: "string", description: "Why this is a false positive — persisted with the rule. Strongly recommended." },
|
|
130
|
+
},
|
|
131
|
+
required: ["path"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
116
134
|
],
|
|
117
135
|
}));
|
|
118
136
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
@@ -226,6 +244,28 @@ export function createServer() {
|
|
|
226
244
|
}
|
|
227
245
|
return textResult(results);
|
|
228
246
|
}
|
|
247
|
+
case "suppress_finding": {
|
|
248
|
+
const suppressPath = args?.path;
|
|
249
|
+
if (!suppressPath)
|
|
250
|
+
return errorResult("path is required");
|
|
251
|
+
const rules = Array.isArray(args?.rules)
|
|
252
|
+
? args.rules.map((r) => String(r))
|
|
253
|
+
: undefined;
|
|
254
|
+
const reason = args?.reason;
|
|
255
|
+
try {
|
|
256
|
+
const result = writeSuppression({ paths: [suppressPath], rules, reason });
|
|
257
|
+
return textResult({
|
|
258
|
+
ok: true,
|
|
259
|
+
file: result.file,
|
|
260
|
+
action: result.action,
|
|
261
|
+
entry: result.entry,
|
|
262
|
+
suppression_count: result.suppressionCount,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
return errorResult(`Failed to write suppression: ${err.message || err}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
229
269
|
default:
|
|
230
270
|
return errorResult(`Unknown tool: ${name}`);
|
|
231
271
|
}
|
|
@@ -27,8 +27,8 @@ const POLICY_FILE_CANDIDATES = [
|
|
|
27
27
|
* For each directory, check candidates in precedence order; the first hit
|
|
28
28
|
* wins. The walk only ascends — siblings are not considered.
|
|
29
29
|
*/
|
|
30
|
-
export function findPolicyFile() {
|
|
31
|
-
let dir =
|
|
30
|
+
export function findPolicyFile(startDir = process.cwd()) {
|
|
31
|
+
let dir = startDir;
|
|
32
32
|
const root = getGitRoot() || path.parse(dir).root;
|
|
33
33
|
while (true) {
|
|
34
34
|
for (const filename of POLICY_FILE_CANDIDATES) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
import { findPolicyFile } from "./policy-loader.js";
|
|
6
|
+
function getGitRoot(cwd) {
|
|
7
|
+
try {
|
|
8
|
+
return execSync("git rev-parse --show-toplevel", {
|
|
9
|
+
cwd,
|
|
10
|
+
encoding: "utf-8",
|
|
11
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
12
|
+
}).trim();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a rule for dedup comparison: an ignore rule is "the same" if it
|
|
20
|
+
* targets the same set of paths and the same set of rule names (order- and
|
|
21
|
+
* duplicate-insensitive). Reason is intentionally excluded — re-suppressing
|
|
22
|
+
* the same scope just updates the reason.
|
|
23
|
+
*/
|
|
24
|
+
function ruleKey(paths, rules) {
|
|
25
|
+
const norm = (xs) => Array.from(new Set((xs ?? []).map((x) => String(x)))).sort();
|
|
26
|
+
return JSON.stringify({ paths: norm(paths), rules: norm(rules) });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Persist a finding suppression into the project's `.rafter.yml` `ignore`
|
|
30
|
+
* list. Resolves the policy file via the same precedence the loader uses;
|
|
31
|
+
* if none exists, creates a canonical `.rafter.yml` at the git root (or cwd).
|
|
32
|
+
*
|
|
33
|
+
* Merge semantics: if an existing ignore rule targets the same paths + rules,
|
|
34
|
+
* its reason is updated in place rather than appending a duplicate.
|
|
35
|
+
*/
|
|
36
|
+
export function writeSuppression(input) {
|
|
37
|
+
const paths = (input.paths ?? []).map((p) => String(p)).filter((p) => p.length > 0);
|
|
38
|
+
if (paths.length === 0) {
|
|
39
|
+
throw new Error('"paths" must be a non-empty array of file paths or globs.');
|
|
40
|
+
}
|
|
41
|
+
const rules = Array.isArray(input.rules)
|
|
42
|
+
? input.rules.map((r) => String(r)).filter((r) => r.length > 0)
|
|
43
|
+
: undefined;
|
|
44
|
+
const reason = typeof input.reason === "string" && input.reason.trim() ? input.reason.trim() : undefined;
|
|
45
|
+
const baseDir = input.cwd || process.cwd();
|
|
46
|
+
// Resolve target file: existing policy file wins; else canonical dotfile at git root / cwd.
|
|
47
|
+
let target = findPolicyFile(baseDir);
|
|
48
|
+
let action;
|
|
49
|
+
let raw = {};
|
|
50
|
+
if (target && fs.existsSync(target)) {
|
|
51
|
+
const content = fs.readFileSync(target, "utf-8");
|
|
52
|
+
const parsed = yaml.load(content);
|
|
53
|
+
raw = parsed && typeof parsed === "object" ? parsed : {};
|
|
54
|
+
action = "appended";
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const root = getGitRoot(baseDir) || baseDir;
|
|
58
|
+
target = path.join(root, ".rafter.yml");
|
|
59
|
+
action = "created";
|
|
60
|
+
}
|
|
61
|
+
const ignoreList = Array.isArray(raw.ignore) ? raw.ignore : [];
|
|
62
|
+
const newEntry = { paths };
|
|
63
|
+
if (rules && rules.length > 0)
|
|
64
|
+
newEntry.rules = rules;
|
|
65
|
+
if (reason)
|
|
66
|
+
newEntry.reason = reason;
|
|
67
|
+
const key = ruleKey(paths, rules);
|
|
68
|
+
const existing = ignoreList.find((e) => e && typeof e === "object" && Array.isArray(e.paths) && ruleKey(e.paths, e.rules) === key);
|
|
69
|
+
if (existing) {
|
|
70
|
+
// Same scope already suppressed — update the reason in place.
|
|
71
|
+
if (reason)
|
|
72
|
+
existing.reason = reason;
|
|
73
|
+
else
|
|
74
|
+
delete existing.reason;
|
|
75
|
+
if (action !== "created")
|
|
76
|
+
action = "updated";
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
ignoreList.push(newEntry);
|
|
80
|
+
}
|
|
81
|
+
raw.ignore = ignoreList;
|
|
82
|
+
const dumped = yaml.dump(raw, { lineWidth: 100, noRefs: true, sortKeys: false });
|
|
83
|
+
const dir = path.dirname(target);
|
|
84
|
+
if (!fs.existsSync(dir))
|
|
85
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
86
|
+
fs.writeFileSync(target, dumped, "utf-8");
|
|
87
|
+
return {
|
|
88
|
+
file: target,
|
|
89
|
+
action,
|
|
90
|
+
entry: existing ? { ...newEntry, ...(existing.reason ? { reason: existing.reason } : {}) } : newEntry,
|
|
91
|
+
suppressionCount: ignoreList.length,
|
|
92
|
+
};
|
|
93
|
+
}
|
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.8.
|
|
4
|
+
version: 0.8.7
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|
|
@@ -53,7 +53,7 @@ If the finding is a leaked secret that was committed:
|
|
|
53
53
|
|
|
54
54
|
## Suppression — When It's OK
|
|
55
55
|
|
|
56
|
-
Suppress only when the finding is a real false positive *for this context*, with a written reason.
|
|
56
|
+
Suppress only when the finding is a real false positive *for this context*, with a written reason. Three mechanisms:
|
|
57
57
|
|
|
58
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
59
|
```yaml
|
|
@@ -62,7 +62,8 @@ Suppress only when the finding is a real false positive *for this context*, with
|
|
|
62
62
|
rules: ["AWS Access Key ID"] # omit `rules` to suppress every finding on those paths
|
|
63
63
|
reason: "fake test keys — no live path"
|
|
64
64
|
```
|
|
65
|
-
|
|
65
|
+
Each `rules` entry matches (case-insensitively) the finding's **rule name** (e.g. `AWS Access Key ID`) **or** its **rule id** (e.g. `R-6D5E2`) — use the name for local pattern findings, the id for remote SAST/SCA findings. Path globs are gitignore-style: `*` stays within a path segment, `**` crosses segments, a bare name matches the basename. The same `.rafter.yml ignore` block is honored by **local** scans and **remote `rafter run`** alike. 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
|
+
- **MCP `suppress_finding` tool**: agents can triage a false positive directly through the MCP — it writes the same `.rafter.yml` `ignore` rule above (path, optional rule names, reason). No hand-editing required.
|
|
66
67
|
- **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.
|
|
67
68
|
|
|
68
69
|
Never suppress by:
|