@rafter-security/cli 0.8.9 → 0.8.10

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.
@@ -112,7 +112,9 @@ function claudeCodeHooks() {
112
112
  delete settings.hooks.SessionStart;
113
113
  }
114
114
  settings.hooks.PreToolUse.push({ matcher: "Bash", hooks: [pre] }, { matcher: "Write|Edit", hooks: [pre] });
115
- settings.hooks.PostToolUse.push({ matcher: ".*", hooks: [post] });
115
+ // Narrow to tools that produce scannable output (shell output + file
116
+ // writes); avoids firing posttool on every Read/MCP call (latency).
117
+ settings.hooks.PostToolUse.push({ matcher: "Bash|Write|Edit|MultiEdit", hooks: [post] });
116
118
  writeJson(settingsPath, settings);
117
119
  },
118
120
  uninstall: () => {
@@ -268,7 +268,10 @@ function installClaudeCodeHooks(root) {
268
268
  }
269
269
  // Add Rafter hooks
270
270
  settings.hooks.PreToolUse.push({ matcher: "Bash", hooks: [preHook] }, { matcher: "Write|Edit", hooks: [preHook] });
271
- settings.hooks.PostToolUse.push({ matcher: ".*", hooks: [postHook] });
271
+ // Narrow to tools that produce scannable output (shell output + file
272
+ // writes). Firing posttool on every tool — including Read and MCP calls —
273
+ // added latency to operations that never produce secrets to redact.
274
+ settings.hooks.PostToolUse.push({ matcher: "Bash|Write|Edit|MultiEdit", hooks: [postHook] });
272
275
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
273
276
  console.log(fmt.success(`Installed PreToolUse hooks to ${settingsPath}`));
274
277
  console.log(fmt.success(`Installed PostToolUse hooks to ${settingsPath}`));
@@ -4,6 +4,11 @@ import { AuditLogger } from "../../core/audit-logger.js";
4
4
  export function createHookPosttoolCommand() {
5
5
  return new Command("posttool")
6
6
  .description("PostToolUse hook handler (reads stdin, redacts secrets in output, writes JSON to stdout)")
7
+ // Tolerate extra flags/args the host harness appends to the hook command
8
+ // (e.g. Claude Code adds `--hook-json <data>`). Hook input comes from stdin,
9
+ // so anything else is unused — discard it instead of erroring out.
10
+ .allowUnknownOption()
11
+ .allowExcessArguments()
7
12
  .option("--format <format>", "Output format: claude (default, also Codex/Continue), cursor, gemini, windsurf", "claude")
8
13
  .action(async (opts) => {
9
14
  const format = (opts.format || "claude");
@@ -65,6 +65,11 @@ function formatApprovalMessage(command, evaluation) {
65
65
  export function createHookPretoolCommand() {
66
66
  return new Command("pretool")
67
67
  .description("PreToolUse hook handler (reads stdin, writes JSON decision to stdout)")
68
+ // Tolerate extra flags/args the host harness appends to the hook command
69
+ // (e.g. Claude Code adds `--hook-json <data>`). Hook input comes from stdin,
70
+ // so anything else is unused — discard it instead of erroring out.
71
+ .allowUnknownOption()
72
+ .allowExcessArguments()
68
73
  .option("--format <format>", "Output format: claude (default, also Codex/Continue), cursor, gemini, windsurf", "claude")
69
74
  .action(async (opts) => {
70
75
  const format = (opts.format || "claude");
@@ -1,6 +1,6 @@
1
1
  import { ConfigManager } from "./config-manager.js";
2
2
  import { AuditLogger } from "./audit-logger.js";
3
- import { assessCommandRisk } from "./risk-rules.js";
3
+ import { assessCommandRisk, matchedCriticalPattern } from "./risk-rules.js";
4
4
  export class CommandInterceptor {
5
5
  constructor() {
6
6
  this.config = new ConfigManager();
@@ -10,13 +10,39 @@ export class CommandInterceptor {
10
10
  * Evaluate if a command should be allowed
11
11
  */
12
12
  evaluate(command) {
13
+ const riskLevel = this.assessRisk(command);
14
+ // Unconditional hard-block: catastrophic destructive commands (rm -rf /,
15
+ // fork bombs, disk wipes, mkfs, …) are NEVER allowed, regardless of the
16
+ // configured policy — or its absence. Security must not depend on a policy
17
+ // being present (the default config may be missing one) or on the chosen
18
+ // mode (even allow-all / a custom deny-list cannot opt out of these).
19
+ if (riskLevel === "critical") {
20
+ return {
21
+ command,
22
+ riskLevel,
23
+ allowed: false,
24
+ requiresApproval: false,
25
+ reason: "Matches built-in blocked pattern (critical destructive command)",
26
+ matchedPattern: matchedCriticalPattern(command) ?? "builtin:critical-destructive"
27
+ };
28
+ }
13
29
  const cfg = this.config.loadWithPolicy();
14
30
  const policy = cfg.agent?.commandPolicy;
15
31
  if (!policy) {
16
- // No policy configured, allow by default but still assess risk
32
+ // No policy configured — fall back to safe built-in defaults rather than
33
+ // allow-all: high-risk commands still require approval.
34
+ if (riskLevel === "high") {
35
+ return {
36
+ command,
37
+ riskLevel,
38
+ allowed: false,
39
+ requiresApproval: true,
40
+ reason: "High risk command requires approval"
41
+ };
42
+ }
17
43
  return {
18
44
  command,
19
- riskLevel: this.assessRisk(command),
45
+ riskLevel,
20
46
  allowed: true,
21
47
  requiresApproval: false
22
48
  };
@@ -87,3 +87,17 @@ export function assessCommandRisk(command) {
87
87
  }
88
88
  return "low";
89
89
  }
90
+ /**
91
+ * Return the source of the first CRITICAL pattern matching the command, or null.
92
+ * Mirrors assessCommandRisk's lowercasing. Intended to be called only once a
93
+ * command is already classified "critical" (safe-prefix exclusion is handled by
94
+ * assessCommandRisk), to surface *which* built-in rule matched.
95
+ */
96
+ export function matchedCriticalPattern(command) {
97
+ const cmd = command.toLowerCase().trim();
98
+ for (const pattern of CRITICAL_PATTERNS) {
99
+ if (pattern.test(cmd))
100
+ return pattern.source;
101
+ }
102
+ return null;
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rafter-security/cli",
3
- "version": "0.8.9",
3
+ "version": "0.8.10",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,15 +31,15 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@modelcontextprotocol/sdk": "^1.27.1",
34
- "axios": "^1.13.5",
34
+ "axios": "^1.16.0",
35
35
  "chalk": "^5.3.0",
36
36
  "chokidar": "^5.0.0",
37
37
  "commander": "^11.1.0",
38
38
  "dotenv": "^16.4.5",
39
- "js-yaml": "^4.1.0",
39
+ "js-yaml": "^4.2.0",
40
40
  "minimatch": "^10.2.4",
41
41
  "ora": "^7.0.1",
42
- "tar": "^7.5.10"
42
+ "tar": "^7.5.16"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/js-yaml": "^4.0.9",
@@ -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.9
4
+ version: 0.8.10
5
5
  homepage: https://rafter.so
6
6
  metadata:
7
7
  openclaw: