@rafter-security/cli 0.10.3 → 0.10.4
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/core/command-interceptor.js +43 -1
- package/dist/core/config-defaults.js +2 -0
- package/dist/core/config-manager.js +33 -3
- package/dist/core/policy-loader.js +9 -0
- package/dist/core/risk-rules.js +23 -0
- package/dist/scanners/secret-patterns.js +28 -0
- package/package.json +1 -1
- package/resources/rafter-security-skill.md +1 -1
- package/resources/skills/rafter/docs/guardrails.md +28 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigManager } from "./config-manager.js";
|
|
2
2
|
import { AuditLogger } from "./audit-logger.js";
|
|
3
|
-
import { assessCommandRisk, matchedCriticalPattern, sanitizeCommandForMatching, } from "./risk-rules.js";
|
|
3
|
+
import { assessCommandRisk, matchedCriticalPattern, sanitizeCommandForMatching, isChainedCommand, } from "./risk-rules.js";
|
|
4
4
|
export class CommandInterceptor {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.config = new ConfigManager();
|
|
@@ -67,6 +67,48 @@ export class CommandInterceptor {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
// Check the positive allowlist. Deliberately AFTER blockedPatterns and
|
|
71
|
+
// BEFORE requireApproval: a deny rule always wins, and an allow rule's
|
|
72
|
+
// whole job is to suppress the approval prompt for a known-safe command.
|
|
73
|
+
//
|
|
74
|
+
// Two guards keep an allowlist from becoming a hole in the guard rail:
|
|
75
|
+
//
|
|
76
|
+
// - A `critical` command is never allowlistable. NOTE: this guard is
|
|
77
|
+
// currently UNREACHABLE — evaluate() hard-blocks critical at the top of
|
|
78
|
+
// the method, before this loop — and a mutation sweep proved it:
|
|
79
|
+
// deleting the guard leaves every test green, in both runtimes. Kept as
|
|
80
|
+
// defence in depth, because it becomes the only protection the day that
|
|
81
|
+
// early block is narrowed. Do not write a test claiming to exercise it;
|
|
82
|
+
// such a test passes with the guard deleted.
|
|
83
|
+
// - A match does not apply when the command holds more than one
|
|
84
|
+
// statement. Patterns are unanchored by request, so without this
|
|
85
|
+
// "^git push" would wave through `rm -rf / && git push` — or, via the
|
|
86
|
+
// newline the original regex missed, anything on a second line.
|
|
87
|
+
// Defence in depth behind the config validator: a non-array here is not
|
|
88
|
+
// merely wrong, it is dangerous. A bare string iterates as CHARACTERS, and
|
|
89
|
+
// the first one of `"^git status"` is `^`, which matches every command —
|
|
90
|
+
// the allowlist would allow everything. The validator catches the shape
|
|
91
|
+
// `config set` writes; this catches every other way it could arrive.
|
|
92
|
+
const allowedPatterns = Array.isArray(policy.allowedPatterns) ? policy.allowedPatterns : [];
|
|
93
|
+
for (const pattern of allowedPatterns) {
|
|
94
|
+
if (!this.matchesPattern(command, pattern))
|
|
95
|
+
continue;
|
|
96
|
+
if (isChainedCommand(command)) {
|
|
97
|
+
// Fall through to normal classification rather than allowing.
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (this.assessRisk(command) === "critical") {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
command,
|
|
105
|
+
riskLevel: "low",
|
|
106
|
+
allowed: true,
|
|
107
|
+
requiresApproval: false,
|
|
108
|
+
reason: `Matches allowed pattern: ${pattern}`,
|
|
109
|
+
matchedPattern: pattern
|
|
110
|
+
};
|
|
111
|
+
}
|
|
70
112
|
// Check approval patterns
|
|
71
113
|
for (const pattern of policy.requireApproval) {
|
|
72
114
|
if (this.matchesPattern(command, pattern)) {
|
|
@@ -54,6 +54,8 @@ export function getDefaultConfig() {
|
|
|
54
54
|
mode: "approve-dangerous",
|
|
55
55
|
blockedPatterns: [...DEFAULT_BLOCKED_PATTERNS],
|
|
56
56
|
requireApproval: [...DEFAULT_REQUIRE_APPROVAL],
|
|
57
|
+
// Empty by default: an allowlist is opt-in, per project.
|
|
58
|
+
allowedPatterns: [],
|
|
57
59
|
},
|
|
58
60
|
outputFiltering: {
|
|
59
61
|
redactSecrets: true,
|
|
@@ -73,6 +73,10 @@ function validateConfig(raw) {
|
|
|
73
73
|
console.error('Warning: config "agent.commandPolicy.blockedPatterns" must be an array of strings — using default.');
|
|
74
74
|
cp.blockedPatterns = [...defaults.agent.commandPolicy.blockedPatterns];
|
|
75
75
|
}
|
|
76
|
+
if (cp.allowedPatterns !== undefined && (!Array.isArray(cp.allowedPatterns) || !cp.allowedPatterns.every((v) => typeof v === "string"))) {
|
|
77
|
+
console.error('Warning: config "agent.commandPolicy.allowedPatterns" must be an array of strings — using default.');
|
|
78
|
+
cp.allowedPatterns = [...(defaults.agent.commandPolicy.allowedPatterns ?? [])];
|
|
79
|
+
}
|
|
76
80
|
if (cp.requireApproval !== undefined && (!Array.isArray(cp.requireApproval) || !cp.requireApproval.every((v) => typeof v === "string"))) {
|
|
77
81
|
console.error('Warning: config "agent.commandPolicy.requireApproval" must be an array of strings — using default.');
|
|
78
82
|
cp.requireApproval = [...defaults.agent.commandPolicy.requireApproval];
|
|
@@ -285,10 +289,22 @@ export class ConfigManager {
|
|
|
285
289
|
const policy = loadPolicy();
|
|
286
290
|
if (!policy)
|
|
287
291
|
return config;
|
|
288
|
-
// Ensure agent block exists
|
|
292
|
+
// Ensure agent block exists, AND that commandPolicy inside it does.
|
|
293
|
+
//
|
|
294
|
+
// Checking only for `agent` was not enough. A config file that carries an
|
|
295
|
+
// `agent` block without a `commandPolicy` key — a partial or hand-edited
|
|
296
|
+
// ~/.rafter/config.json, which is a normal thing to have — reaches the
|
|
297
|
+
// assignments below and throws
|
|
298
|
+
// TypeError: Cannot set properties of undefined (setting 'mode')
|
|
299
|
+
// the moment the repo also has a .rafter.yml with a command_policy block.
|
|
300
|
+
// Found 2026-09-10 by an end-to-end test that loads a real config instead
|
|
301
|
+
// of a stub; the stubbed unit tests could not see it.
|
|
302
|
+
const agentDefaults = getDefaultConfig().agent;
|
|
289
303
|
if (!config.agent) {
|
|
290
|
-
|
|
291
|
-
|
|
304
|
+
config.agent = agentDefaults;
|
|
305
|
+
}
|
|
306
|
+
if (!config.agent.commandPolicy) {
|
|
307
|
+
config.agent.commandPolicy = { ...agentDefaults.commandPolicy };
|
|
292
308
|
}
|
|
293
309
|
// Risk level
|
|
294
310
|
if (policy.riskLevel && config.agent) {
|
|
@@ -465,6 +481,8 @@ export function mergeCommandPolicy(target, project, allowOverride) {
|
|
|
465
481
|
target.blockedPatterns = project.blockedPatterns;
|
|
466
482
|
if (project.requireApproval)
|
|
467
483
|
target.requireApproval = project.requireApproval;
|
|
484
|
+
if (project.allowedPatterns)
|
|
485
|
+
target.allowedPatterns = project.allowedPatterns;
|
|
468
486
|
return;
|
|
469
487
|
}
|
|
470
488
|
if (project.mode && project.mode !== target.mode) {
|
|
@@ -484,4 +502,16 @@ export function mergeCommandPolicy(target, project, allowOverride) {
|
|
|
484
502
|
if (project.requireApproval) {
|
|
485
503
|
target.requireApproval = unionPatterns(target.requireApproval, project.requireApproval);
|
|
486
504
|
}
|
|
505
|
+
// allowedPatterns is NOT unioned, and that asymmetry is the whole point.
|
|
506
|
+
// Unioning blockedPatterns or requireApproval can only ever ADD restriction,
|
|
507
|
+
// so a project contributing to them is safe. An allowlist is the opposite:
|
|
508
|
+
// it is a grant. Union it and a cloned repo ships
|
|
509
|
+
// command_policy: { allowed_patterns: [".*"] }
|
|
510
|
+
// and waves every non-critical command through — which is precisely the
|
|
511
|
+
// bypass the floor exists to prevent (sable-nz4y / rf-adth). So the owner's
|
|
512
|
+
// allowlist stands and the project's is refused unless the owner has
|
|
513
|
+
// explicitly opted into project override.
|
|
514
|
+
if (project.allowedPatterns) {
|
|
515
|
+
console.error(`Warning: project policy sets agent.commandPolicy.allowed_patterns, which can only loosen command policy — ignoring. Set agent.commandPolicy.allowProjectOverride: true in your global config to allow project policies to loosen command policy.`);
|
|
516
|
+
}
|
|
487
517
|
}
|
|
@@ -83,6 +83,9 @@ function mapPolicy(raw) {
|
|
|
83
83
|
if (Array.isArray(raw.command_policy.require_approval)) {
|
|
84
84
|
policy.commandPolicy.requireApproval = raw.command_policy.require_approval;
|
|
85
85
|
}
|
|
86
|
+
if (Array.isArray(raw.command_policy.allowed_patterns)) {
|
|
87
|
+
policy.commandPolicy.allowedPatterns = raw.command_policy.allowed_patterns;
|
|
88
|
+
}
|
|
86
89
|
}
|
|
87
90
|
if (raw.scan && typeof raw.scan === "object") {
|
|
88
91
|
policy.scan = {};
|
|
@@ -266,6 +269,12 @@ function validatePolicy(policy, raw) {
|
|
|
266
269
|
delete policy.commandPolicy.requireApproval;
|
|
267
270
|
}
|
|
268
271
|
}
|
|
272
|
+
if (policy.commandPolicy.allowedPatterns !== undefined) {
|
|
273
|
+
if (!Array.isArray(policy.commandPolicy.allowedPatterns) || !policy.commandPolicy.allowedPatterns.every((v) => typeof v === "string")) {
|
|
274
|
+
console.error(`Warning: "command_policy.allowed_patterns" must be an array of strings — ignoring.`);
|
|
275
|
+
delete policy.commandPolicy.allowedPatterns;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
269
278
|
}
|
|
270
279
|
if (policy.scan) {
|
|
271
280
|
if (policy.scan.excludePaths !== undefined) {
|
package/dist/core/risk-rules.js
CHANGED
|
@@ -749,6 +749,29 @@ function stripHeredocBodies(command) {
|
|
|
749
749
|
export function sanitizeCommandForMatching(command) {
|
|
750
750
|
return sanitize(stripHeredocBodies(command), 0);
|
|
751
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* True if the command contains more than one statement.
|
|
754
|
+
*
|
|
755
|
+
* Asked of the TOKENIZER rather than a regex, deliberately. The first version
|
|
756
|
+
* of this was `/[;|&]|&&|\|\|/`, which omits the newline — and a newline has
|
|
757
|
+
* been a statement separator in this file since rf-6pqx, six lines from where
|
|
758
|
+
* that regex sat. The gap was reachable in one step: with `^git push origin
|
|
759
|
+
* feature/` allowlisted,
|
|
760
|
+
*
|
|
761
|
+
* git push origin feature/x
|
|
762
|
+
* git push --force origin main
|
|
763
|
+
*
|
|
764
|
+
* classified `allow`, because the chain check saw no operator. The agent being
|
|
765
|
+
* gated writes the whole string, so prefixing an allowlisted line is free.
|
|
766
|
+
*
|
|
767
|
+
* The tokenizer already normalises `\n` to `;`, so routing the question through
|
|
768
|
+
* it removes the second, narrower definition instead of widening it. One source
|
|
769
|
+
* of truth for "what separates two commands".
|
|
770
|
+
*/
|
|
771
|
+
export function isChainedCommand(command) {
|
|
772
|
+
const { pieces } = tokenize(command);
|
|
773
|
+
return pieces.some((p) => p.op !== null && CHAIN_OPS.has(p.op));
|
|
774
|
+
}
|
|
752
775
|
/**
|
|
753
776
|
* Assess risk level of a command string.
|
|
754
777
|
*/
|
|
@@ -80,6 +80,34 @@ export const DEFAULT_SECRET_PATTERNS = [
|
|
|
80
80
|
severity: "critical",
|
|
81
81
|
description: "Stripe Restricted API Key detected"
|
|
82
82
|
},
|
|
83
|
+
// OpenAI (rf-f5is / se-wagv, external report). The hook's Write gate is
|
|
84
|
+
// regex-only, and this file had NO OpenAI rule at all — so `sk-proj-` and
|
|
85
|
+
// legacy keys were ALLOWED through the gate at any length, while
|
|
86
|
+
// `rafter secrets` caught them via betterleaks. The two engines disagreed,
|
|
87
|
+
// and the one guarding writes was the blind one.
|
|
88
|
+
//
|
|
89
|
+
// No `(?i)`: these prefixes and their base62 bodies are case-sensitive, and
|
|
90
|
+
// the convention here is that prefixed vendor tokens (ghp_, AKIA, AIza, xox)
|
|
91
|
+
// match case-sensitively. Lower-casing them would only add false positives.
|
|
92
|
+
{
|
|
93
|
+
name: "OpenAI API Key",
|
|
94
|
+
regex: "sk-(proj|svcacct|admin)-[A-Za-z0-9_-]{40,}",
|
|
95
|
+
severity: "critical",
|
|
96
|
+
description: "OpenAI project/service/admin API key detected"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "OpenAI API Key (legacy)",
|
|
100
|
+
regex: "sk-[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20}",
|
|
101
|
+
severity: "critical",
|
|
102
|
+
description: "OpenAI legacy API key detected"
|
|
103
|
+
},
|
|
104
|
+
// Supabase (rf-f5is / se-wagv). Detected by NEITHER engine at any length.
|
|
105
|
+
{
|
|
106
|
+
name: "Supabase Secret Key",
|
|
107
|
+
regex: "sb_secret_[A-Za-z0-9_-]{20,}",
|
|
108
|
+
severity: "critical",
|
|
109
|
+
description: "Supabase secret key detected"
|
|
110
|
+
},
|
|
83
111
|
// Twilio
|
|
84
112
|
{
|
|
85
113
|
name: "Twilio API Key",
|
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.10.
|
|
4
|
+
version: 0.10.4
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|
|
@@ -24,23 +24,46 @@ Every command (Bash-like tool call) gets classified into one of four tiers by `s
|
|
|
24
24
|
| `high` | Destructive or privileged (force push, `sudo`, broad file deletion, curl | sh) | **prompt** the agent / user for approval |
|
|
25
25
|
| `critical` | Likely irreversible damage (`rm -rf /`, DB drop, wiping .git, repo-wide chmod) | **block** hard |
|
|
26
26
|
|
|
27
|
-
Tiers are derived from regex patterns in `risk-rules.ts` (`CRITICAL_PATTERNS`, `HIGH_PATTERNS`, `MEDIUM_PATTERNS`) plus a `SAFE_PREFIX` allowlist.
|
|
27
|
+
Tiers are derived from regex patterns in `risk-rules.ts` (`CRITICAL_PATTERNS`, `HIGH_PATTERNS`, `MEDIUM_PATTERNS`) plus a `SAFE_PREFIX` allowlist. A command holding more than one statement disqualifies the safe-prefix shortcut. Statement separators are whatever the tokenizer treats as one — `&&`, `||`, `;`, `|`, `&`, and a NEWLINE — rather than a hand-kept list; the newline was missing from an earlier hand-kept copy and that was a live bypass.
|
|
28
28
|
|
|
29
29
|
## Policy Overrides
|
|
30
30
|
|
|
31
31
|
`.rafter.yml` (project) and `~/.rafter/config.yml` (global) can override defaults:
|
|
32
32
|
|
|
33
33
|
```yaml
|
|
34
|
-
|
|
34
|
+
command_policy:
|
|
35
35
|
blocked_patterns:
|
|
36
36
|
- "terraform destroy"
|
|
37
37
|
require_approval:
|
|
38
38
|
- "^npm publish"
|
|
39
|
-
|
|
40
|
-
- "^pnpm run test"
|
|
39
|
+
allowed_patterns:
|
|
40
|
+
- "^pnpm run test" # force low, skipping the approval prompt
|
|
41
|
+
- "git push --force-with-lease"
|
|
41
42
|
```
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
**On `allowed_patterns`.** Until 2026-09-07 this section documented a
|
|
45
|
+
`risk.allow` key that was never implemented — a customer went looking for it
|
|
46
|
+
and found nothing. The real key is `command_policy.allowed_patterns`, and it
|
|
47
|
+
now exists.
|
|
48
|
+
|
|
49
|
+
It is a positive allowlist for the known-safe command that trips a broad tier:
|
|
50
|
+
the motivating case is `git push --force-with-lease` to a feature branch on a
|
|
51
|
+
repo whose `main` is protected server-side, which classifies `high` and prompts
|
|
52
|
+
on every push even though the dangerous version cannot land. Dropping
|
|
53
|
+
`risk_level` to silence that is too blunt — it would also stop prompting for
|
|
54
|
+
`sudo` and `curl | sh`.
|
|
55
|
+
|
|
56
|
+
Three properties keep an allowlist from becoming a hole in the guard rail:
|
|
57
|
+
|
|
58
|
+
1. **`blocked_patterns` always wins.** An allow rule never re-opens what a deny
|
|
59
|
+
rule closed.
|
|
60
|
+
2. **`critical` is never allowlistable.** `rm -rf /`, a DB drop and wiping
|
|
61
|
+
`.git` stay blocked whatever the config says.
|
|
62
|
+
3. **Chain operators disqualify a match.** Patterns are unanchored, so without
|
|
63
|
+
this `"git push"` would wave through `rm -rf / && git push`. A chained
|
|
64
|
+
command is classified exactly as it would be with no allowlist configured.
|
|
65
|
+
|
|
66
|
+
Merge order: project `.rafter.yml` > global config > built-in defaults for most keys — but NOT for `command_policy`, which is a floor. A project policy may tighten command policy and never loosen it: `mode` is accepted only if at least as strict, `blocked_patterns` and `require_approval` are unioned, and `allowed_patterns` — being a grant rather than a restriction — is refused outright unless the machine owner sets `agent.commandPolicy.allowProjectOverride: true` in their global config. Dump the effective merged policy with `rafter policy export`.
|
|
44
67
|
|
|
45
68
|
## How to Interpret a Block
|
|
46
69
|
|