@rafter-security/cli 0.11.4 → 0.11.6
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.
|
@@ -23,6 +23,59 @@ export const MAX_TRANSIENT_POLL_FAILURES = 5;
|
|
|
23
23
|
* stop it. This is the backstop for that.
|
|
24
24
|
*/
|
|
25
25
|
export const MAX_TOTAL_TRANSIENT_POLL_FAILURES = 20;
|
|
26
|
+
/**
|
|
27
|
+
* sable-96ex — a 429 during polling is ambiguous in this API: on scan SUBMIT it
|
|
28
|
+
* means "you are out of credits" (exit 3), and on the poll endpoint it would
|
|
29
|
+
* mean "you are going too fast". `Retry-After` is the disambiguator — a quota
|
|
30
|
+
* rejection does not carry one, a rate limiter does — so a 429 is retried here
|
|
31
|
+
* only when the server tells us how long to wait, and fails fast otherwise.
|
|
32
|
+
*
|
|
33
|
+
* Longest Retry-After we honor. A limiter is free to answer "come back in an
|
|
34
|
+
* hour"; a CI job cannot sit there for it, and the failure budget still bounds
|
|
35
|
+
* the total wait either way.
|
|
36
|
+
*/
|
|
37
|
+
export const MAX_RETRY_AFTER_MS = 60000;
|
|
38
|
+
/**
|
|
39
|
+
* `Retry-After` in milliseconds, or null when it is absent or unusable.
|
|
40
|
+
*
|
|
41
|
+
* Only the delay-seconds form is honored. The HTTP-date form is deliberately
|
|
42
|
+
* not parsed: the composite action has to make the same decision in bash on
|
|
43
|
+
* whatever `date` the runner ships, and a rule the three surfaces cannot state
|
|
44
|
+
* identically is worse than a narrow one they can. An unparseable header is
|
|
45
|
+
* treated as absent — which means fail fast, the conservative direction.
|
|
46
|
+
*/
|
|
47
|
+
export function retryAfterMs(e) {
|
|
48
|
+
const headers = e?.response?.headers;
|
|
49
|
+
if (!headers)
|
|
50
|
+
return null;
|
|
51
|
+
let raw;
|
|
52
|
+
if (typeof headers.get === "function")
|
|
53
|
+
raw = headers.get("retry-after");
|
|
54
|
+
if (raw === undefined || raw === null) {
|
|
55
|
+
for (const k of Object.keys(headers)) {
|
|
56
|
+
if (k.toLowerCase() === "retry-after") {
|
|
57
|
+
raw = headers[k];
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Two Retry-Afters — an origin's and a proxy's, say — is not a delay we can
|
|
63
|
+
// act on, so it counts as absent like any other unusable value. Python gets
|
|
64
|
+
// this for free (requests joins duplicates as "5, 900", which fails the digit
|
|
65
|
+
// test) and bash counts the header lines; all three must answer the same.
|
|
66
|
+
if (Array.isArray(raw)) {
|
|
67
|
+
if (raw.length !== 1)
|
|
68
|
+
return null;
|
|
69
|
+
raw = raw[0];
|
|
70
|
+
}
|
|
71
|
+
if (raw === undefined || raw === null)
|
|
72
|
+
return null;
|
|
73
|
+
const text = String(raw).trim();
|
|
74
|
+
if (!/^\d+$/.test(text))
|
|
75
|
+
return null;
|
|
76
|
+
// A 400-digit header parses to Infinity; the clamp is what makes that safe.
|
|
77
|
+
return Math.min(Number(text) * 1000, MAX_RETRY_AFTER_MS);
|
|
78
|
+
}
|
|
26
79
|
/** Longest single error detail we will echo back. Servers can be verbose. */
|
|
27
80
|
const MAX_ERROR_DETAIL_CHARS = 200;
|
|
28
81
|
/**
|
|
@@ -42,6 +95,12 @@ function isTransientPollError(e, scanExists) {
|
|
|
42
95
|
}
|
|
43
96
|
if (status === 404)
|
|
44
97
|
return scanExists;
|
|
98
|
+
// 429 is transient only when the server said when to come back. See
|
|
99
|
+
// MAX_RETRY_AFTER_MS: without that header a 429 here is a quota rejection,
|
|
100
|
+
// and retrying one for half a minute before failing anyway is worse than
|
|
101
|
+
// failing now.
|
|
102
|
+
if (status === 429)
|
|
103
|
+
return retryAfterMs(e) !== null;
|
|
45
104
|
return status >= 500 || status === 408;
|
|
46
105
|
}
|
|
47
106
|
function truncate(value) {
|
|
@@ -90,6 +149,19 @@ export function unreadableReportMessage(scan_id, lastError, attempts = MAX_TRANS
|
|
|
90
149
|
`or open the scan in your dashboard at https://rafter.so/dashboard\n` +
|
|
91
150
|
`Last response from the server: ${lastError}`);
|
|
92
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* The give-up message when polling was throttled rather than blocked on an
|
|
154
|
+
* unreadable report. Telling a customer their report could not be read, when
|
|
155
|
+
* what actually happened is that we were rate limited, points them at the
|
|
156
|
+
* wrong thing — and at a `rafter get` that will be throttled too.
|
|
157
|
+
*/
|
|
158
|
+
export function rateLimitedMessage(scan_id, lastError, attempts = MAX_TRANSIENT_POLL_FAILURES) {
|
|
159
|
+
return (`Rafter was rate limited by the API while polling scan ${scan_id} ` +
|
|
160
|
+
`(${attempts} attempts).\n` +
|
|
161
|
+
`The scan itself may still be running — retry with: rafter get ${scan_id}\n` +
|
|
162
|
+
`or open the scan in your dashboard at https://rafter.so/dashboard\n` +
|
|
163
|
+
`Last response from the server: ${lastError}`);
|
|
164
|
+
}
|
|
93
165
|
export const BASE_BACKOFF_MS = 2000;
|
|
94
166
|
/** 2s, 4s, 8s, 16s — the 5th failure gives up rather than sleeping again. */
|
|
95
167
|
export function backoffMs(consecutiveFailures) {
|
|
@@ -115,12 +187,15 @@ class FailureBudget {
|
|
|
115
187
|
this.last = "";
|
|
116
188
|
/** False once any failure carried no HTTP response at all. */
|
|
117
189
|
this.lastReachedServer = true;
|
|
190
|
+
/** True when the failure we gave up on was a throttled 429, not a bad read. */
|
|
191
|
+
this.lastRateLimited = false;
|
|
118
192
|
}
|
|
119
|
-
record(detail, reachedServer) {
|
|
193
|
+
record(detail, reachedServer, rateLimited = false) {
|
|
120
194
|
this.consecutive += 1;
|
|
121
195
|
this.total += 1;
|
|
122
196
|
this.last = detail;
|
|
123
197
|
this.lastReachedServer = reachedServer;
|
|
198
|
+
this.lastRateLimited = rateLimited;
|
|
124
199
|
return this.consecutive;
|
|
125
200
|
}
|
|
126
201
|
/** A success clears the consecutive run, but never refunds the total. */
|
|
@@ -132,6 +207,21 @@ class FailureBudget {
|
|
|
132
207
|
this.total >= MAX_TOTAL_TRANSIENT_POLL_FAILURES);
|
|
133
208
|
}
|
|
134
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Retries are printed to stderr, not just into the spinner: ora renders
|
|
212
|
+
* nothing on a non-TTY, and CI is exactly where this diagnostic matters.
|
|
213
|
+
*/
|
|
214
|
+
function makeRetryNotice(quiet) {
|
|
215
|
+
if (quiet)
|
|
216
|
+
return undefined;
|
|
217
|
+
return (attempt, waitMs, detail, rateLimited) => {
|
|
218
|
+
const what = rateLimited
|
|
219
|
+
? `Rate limited by the API (${detail})`
|
|
220
|
+
: `Report not readable yet (${detail})`;
|
|
221
|
+
console.error(`${what}; retrying in ${Math.round(waitMs / 1000)}s ` +
|
|
222
|
+
`(${attempt}/${MAX_TRANSIENT_POLL_FAILURES})`);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
135
225
|
/**
|
|
136
226
|
* One poll, with retry/backoff over transient failures.
|
|
137
227
|
* Non-transient errors are rethrown for the caller to classify.
|
|
@@ -152,12 +242,20 @@ async function pollUntilReadable(scan_id, headers, fmt, budget, scanExists, onRe
|
|
|
152
242
|
catch (e) {
|
|
153
243
|
if (!isTransientPollError(e, scanExists))
|
|
154
244
|
throw e;
|
|
155
|
-
|
|
245
|
+
// Non-null only for a 429 that carried a usable Retry-After — the sole
|
|
246
|
+
// reason such a 429 got past the classifier above.
|
|
247
|
+
const retryAfter = e?.response?.status === 429 ? retryAfterMs(e) : null;
|
|
248
|
+
const attempt = budget.record(describeHttpError(e), e?.response?.status !== undefined, retryAfter !== null);
|
|
156
249
|
if (budget.exhausted) {
|
|
157
|
-
throw new PollGaveUpError(
|
|
250
|
+
throw new PollGaveUpError(budget.lastRateLimited
|
|
251
|
+
? rateLimitedMessage(scan_id, budget.last, budget.total)
|
|
252
|
+
: unreadableReportMessage(scan_id, budget.last, budget.total, budget.lastReachedServer));
|
|
158
253
|
}
|
|
159
|
-
|
|
160
|
-
|
|
254
|
+
// The server named the delay; obey it instead of our own schedule. It
|
|
255
|
+
// still spends a failure from the budget, so an endlessly-throttling
|
|
256
|
+
// API cannot keep the loop alive.
|
|
257
|
+
const waitMs = retryAfter ?? backoffMs(attempt);
|
|
258
|
+
onRetry?.(attempt, waitMs, budget.last, retryAfter !== null);
|
|
161
259
|
await new Promise((r) => setTimeout(r, waitMs));
|
|
162
260
|
}
|
|
163
261
|
}
|
|
@@ -171,25 +269,12 @@ async function pollUntilReadable(scan_id, headers, fmt, budget, scanExists, onRe
|
|
|
171
269
|
*/
|
|
172
270
|
export async function fetchScanWithRetry(scan_id, headers, fmt, quiet) {
|
|
173
271
|
const budget = new FailureBudget();
|
|
174
|
-
|
|
175
|
-
? undefined
|
|
176
|
-
: (attempt, waitMs, detail) => {
|
|
177
|
-
console.error(`Report not readable yet (${detail}); retrying in ${Math.round(waitMs / 1000)}s ` +
|
|
178
|
-
`(${attempt}/${MAX_TRANSIENT_POLL_FAILURES})`);
|
|
179
|
-
};
|
|
180
|
-
return pollUntilReadable(scan_id, headers, fmt, budget, false, onRetry);
|
|
272
|
+
return pollUntilReadable(scan_id, headers, fmt, budget, false, makeRetryNotice(quiet));
|
|
181
273
|
}
|
|
182
274
|
const IN_PROGRESS = ["queued", "pending", "processing"];
|
|
183
275
|
export async function handleScanStatus(scan_id, headers, fmt, quiet) {
|
|
184
276
|
const budget = new FailureBudget();
|
|
185
|
-
|
|
186
|
-
// nothing on a non-TTY, and CI is exactly where this diagnostic matters.
|
|
187
|
-
const onRetry = quiet
|
|
188
|
-
? undefined
|
|
189
|
-
: (attempt, waitMs, detail) => {
|
|
190
|
-
console.error(`Report not readable yet (${detail}); retrying in ${Math.round(waitMs / 1000)}s ` +
|
|
191
|
-
`(${attempt}/${MAX_TRANSIENT_POLL_FAILURES})`);
|
|
192
|
-
};
|
|
277
|
+
const onRetry = makeRetryNotice(quiet);
|
|
193
278
|
// First poll. A 404 here really does mean "no such scan" — do not retry it.
|
|
194
279
|
// Transient 5xx IS retried, so that the `rafter get <id>` this command
|
|
195
280
|
// recommends on failure is not itself defeated by one bad read.
|
|
@@ -13,6 +13,7 @@ import { shellQuote } from "../agent/exec.js";
|
|
|
13
13
|
import { scanAddedDiffLines } from "../../scanners/git-diff-scan.js";
|
|
14
14
|
import { parseUnifiedDiffAddedLines, gitDiffMaxBuffer } from "../../utils/git-diff.js";
|
|
15
15
|
import { execSync } from "child_process";
|
|
16
|
+
import fs from "fs";
|
|
16
17
|
import path from "path";
|
|
17
18
|
/**
|
|
18
19
|
* Load the policy-merged scan config + suppression list the same way scan.ts
|
|
@@ -318,14 +319,29 @@ function writesRafterSecurityConfig(filePath) {
|
|
|
318
319
|
const expanded = filePath.startsWith("~")
|
|
319
320
|
? path.join(os.homedir(), filePath.slice(1))
|
|
320
321
|
: filePath;
|
|
321
|
-
|
|
322
|
-
|
|
322
|
+
// Compare real paths, as Python's Path.resolve() does: a symlink into the
|
|
323
|
+
// rafter dir must not be a way around this check (sable-rxqr).
|
|
324
|
+
const target = realpathNearest(path.resolve(expanded));
|
|
325
|
+
const rafterDir = realpathNearest(path.resolve(getRafterDir()));
|
|
323
326
|
return target === rafterDir || target.startsWith(rafterDir + path.sep);
|
|
324
327
|
}
|
|
325
328
|
catch {
|
|
326
329
|
return false;
|
|
327
330
|
}
|
|
328
331
|
}
|
|
332
|
+
/** Real path of `p`, resolving symlinks in its longest existing prefix. */
|
|
333
|
+
function realpathNearest(p) {
|
|
334
|
+
let head = p;
|
|
335
|
+
const tail = [];
|
|
336
|
+
while (!fs.existsSync(head)) {
|
|
337
|
+
const parent = path.dirname(head);
|
|
338
|
+
if (parent === head)
|
|
339
|
+
return p;
|
|
340
|
+
tail.unshift(path.basename(head));
|
|
341
|
+
head = parent;
|
|
342
|
+
}
|
|
343
|
+
return path.join(fs.realpathSync(head), ...tail);
|
|
344
|
+
}
|
|
329
345
|
function evaluateWrite(toolInput) {
|
|
330
346
|
// rf-vnxs: checked FIRST, and before the no-content early return, because a
|
|
331
347
|
// truncating write with empty content disables the hook just as well as one
|
|
@@ -59,9 +59,10 @@ export function loadPolicy(baseDir) {
|
|
|
59
59
|
return null;
|
|
60
60
|
try {
|
|
61
61
|
const content = fs.readFileSync(policyPath, "utf-8");
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
62
|
+
const loaded = yaml.load(content);
|
|
63
|
+
if (!loaded || typeof loaded !== "object")
|
|
64
64
|
return null;
|
|
65
|
+
const parsed = normalizeKeySpelling(loaded);
|
|
65
66
|
return validatePolicy(mapPolicy(parsed), parsed);
|
|
66
67
|
}
|
|
67
68
|
catch (e) {
|
|
@@ -69,6 +70,65 @@ export function loadPolicy(baseDir) {
|
|
|
69
70
|
return null;
|
|
70
71
|
}
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* camelCase spelling -> snake_case key, for every multi-word key the loader
|
|
75
|
+
* reads, per nesting level (sable-req5). The hosted scanner accepts both
|
|
76
|
+
* spellings with snake_case winning on collision; so do both CLIs. Keep this
|
|
77
|
+
* table identical to _CAMEL_ALIASES in python/rafter_cli/core/policy_loader.py.
|
|
78
|
+
*/
|
|
79
|
+
const CAMEL_ALIASES = {
|
|
80
|
+
top: {
|
|
81
|
+
riskLevel: "risk_level",
|
|
82
|
+
commandPolicy: "command_policy",
|
|
83
|
+
excludePaths: "exclude_paths",
|
|
84
|
+
customPatterns: "custom_patterns",
|
|
85
|
+
},
|
|
86
|
+
command_policy: {
|
|
87
|
+
blockedPatterns: "blocked_patterns",
|
|
88
|
+
requireApproval: "require_approval",
|
|
89
|
+
allowedPatterns: "allowed_patterns",
|
|
90
|
+
},
|
|
91
|
+
scan: {
|
|
92
|
+
excludePaths: "exclude_paths",
|
|
93
|
+
customPatterns: "custom_patterns",
|
|
94
|
+
autoUpdateBetterleaks: "auto_update_betterleaks",
|
|
95
|
+
plusRequiresApproval: "plus_requires_approval",
|
|
96
|
+
},
|
|
97
|
+
audit: {
|
|
98
|
+
retentionDays: "retention_days",
|
|
99
|
+
logLevel: "log_level",
|
|
100
|
+
logPath: "log_path",
|
|
101
|
+
},
|
|
102
|
+
"docs.cache": {
|
|
103
|
+
ttlSeconds: "ttl_seconds",
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const isPlainObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
107
|
+
/** Copy `d` with known camelCase keys renamed to snake_case; snake_case wins. */
|
|
108
|
+
function snakeKeys(d, aliases) {
|
|
109
|
+
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
110
|
+
// fromEntries defines own properties, so a "__proto__" key stays a plain key.
|
|
111
|
+
const out = Object.fromEntries(Object.entries(d).filter(([k]) => !has(aliases, k)));
|
|
112
|
+
for (const [camel, snake] of Object.entries(aliases)) {
|
|
113
|
+
if (has(d, camel) && !has(d, snake))
|
|
114
|
+
out[snake] = d[camel];
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
/** Rewrite camelCase policy keys to the snake_case `mapPolicy` reads. */
|
|
119
|
+
function normalizeKeySpelling(loaded) {
|
|
120
|
+
const raw = snakeKeys(loaded, CAMEL_ALIASES.top);
|
|
121
|
+
for (const section of ["command_policy", "scan", "audit"]) {
|
|
122
|
+
if (isPlainObject(raw[section]))
|
|
123
|
+
raw[section] = snakeKeys(raw[section], CAMEL_ALIASES[section]);
|
|
124
|
+
}
|
|
125
|
+
if (Array.isArray(raw.docs)) {
|
|
126
|
+
raw.docs = raw.docs.map((e) => isPlainObject(e) && isPlainObject(e.cache)
|
|
127
|
+
? { ...e, cache: snakeKeys(e.cache, CAMEL_ALIASES["docs.cache"]) }
|
|
128
|
+
: e);
|
|
129
|
+
}
|
|
130
|
+
return raw;
|
|
131
|
+
}
|
|
72
132
|
/**
|
|
73
133
|
* Map snake_case YAML keys to camelCase PolicyFile
|
|
74
134
|
*/
|
package/dist/core/risk-rules.js
CHANGED
|
@@ -41,8 +41,9 @@ const CRITICAL_DIRS = "home|etc|usr|boot|root|sys|proc|lib|lib64|bin|sbin|opt";
|
|
|
41
41
|
* whose stdin the sanitizer redacts (the broadest gap);
|
|
42
42
|
* - a payload split across shell variables (`a=/dev/tc;b=p/…`) or hidden in an
|
|
43
43
|
* unreadable `$(…)`/base64 blob;
|
|
44
|
-
* - the quoted-operand forms of `php -r`, `
|
|
45
|
-
*
|
|
44
|
+
* - the quoted-operand forms of `php -r`, `gawk /inet/`, `telnet`, and the
|
|
45
|
+
* non-standard `rcat`. (socat's quoted `EXEC:`/`SYSTEM:` program is read:
|
|
46
|
+
* socat is code-carrying, sable-gmgh.)
|
|
46
47
|
* `… | sh` and base64-into-shell still degrade to high via shellProgramFromStream.
|
|
47
48
|
*/
|
|
48
49
|
const REVERSE_SHELL_PATTERN_SOURCES = [
|
|
@@ -102,6 +103,19 @@ const CRITICAL_PATTERN_SOURCES = [
|
|
|
102
103
|
];
|
|
103
104
|
export const CRITICAL_PATTERNS = CRITICAL_PATTERN_SOURCES.map((s) => new RegExp(s));
|
|
104
105
|
export const HIGH_PATTERNS = [
|
|
106
|
+
// sable-lbyp: a pseudo-terminal wrapper around rafter's own approval prompt.
|
|
107
|
+
// `rafter agent exec` grants approval only to a person at a TTY; `script`,
|
|
108
|
+
// `expect`, `unbuffer`, `socat` and Python's pty module manufacture one and
|
|
109
|
+
// can type "yes". Wrapping rafter in any of them is itself the signal.
|
|
110
|
+
/\b(?:script|expect|unbuffer|socat)\b.*\brafter(?:-cli)?\s+agent\s+exec\b/,
|
|
111
|
+
// Scoped to `agent exec` exactly as the sibling above is. Without the
|
|
112
|
+
// subcommand this matched ANY rafter invocation wrapped in Python's pty
|
|
113
|
+
// module -- `rafter --version`, `rafter audit`, `rafter secrets scan` all
|
|
114
|
+
// went low -> high. That contradicts this patch's own principle that only
|
|
115
|
+
// `agent exec` carries a command, and in headless CI a HIGH with stdin not
|
|
116
|
+
// a TTY is DENIED outright (exit 1), turning a previously-succeeding call
|
|
117
|
+
// into a hard failure.
|
|
118
|
+
/\bpty\.(?:spawn|fork|openpty)\b.*\brafter(?:-cli)?['",\s]+agent['",\s]+exec\b/,
|
|
105
119
|
/rm\s+(-[a-z]*r[a-z]*\s+)*-[a-z]*f[a-z]*/, // rm -rf, -fr, -r -f, -f -r (any path)
|
|
106
120
|
/rm\s+(-[a-z]*f[a-z]*\s+)*-[a-z]*r[a-z]*/, // rm -fr, reversed
|
|
107
121
|
/sudo\s+rm/,
|
|
@@ -194,6 +208,7 @@ const EVAL_FLAGS = new Set(["-c", "-e", "--command", "--execute", "--eval", "-ex
|
|
|
194
208
|
const TAIL_WRAPPERS = new Set([
|
|
195
209
|
"sudo", "doas", "env", "nohup", "timeout", "nice", "ionice",
|
|
196
210
|
"time", "watch", "setsid", "stdbuf", "chrt", "command",
|
|
211
|
+
"unbuffer", // expect's pty wrapper: delegates to the command that follows (sable-lbyp)
|
|
197
212
|
]);
|
|
198
213
|
/** Commands whose operands are pure text data — searching or printing, never executing. */
|
|
199
214
|
const TEXT_EXECS = new Set(["echo", "printf", "grep", "egrep", "fgrep", "rg", "ag", "ack"]);
|
|
@@ -538,7 +553,12 @@ function processSegment(pieces, depth, out, pipedIntoShell = false, outputExecut
|
|
|
538
553
|
if (!p.quoted && EVAL_FLAGS.has(p.text.toLowerCase()))
|
|
539
554
|
hasEvalFlag = true;
|
|
540
555
|
}
|
|
541
|
-
|
|
556
|
+
// sable-lbyp: rafter's own `agent exec` runs its operand, so the hook must
|
|
557
|
+
// see through its own binary the way it sees through `bash -c`.
|
|
558
|
+
// sable-gmgh: socat's EXEC:/SYSTEM: addresses run a program, so a quoted one
|
|
559
|
+
// (`EXEC:"bash -li",pty`) is a command, not prose.
|
|
560
|
+
const codeCarrying = hasShellExec || hasEvalFlag || EVAL_EXECS.has(exec) || exec === "socat" ||
|
|
561
|
+
rafterExecRunsOperand(pieces, execIdx);
|
|
542
562
|
// sable-c6an. Two questions the code conflated, and conflating them gets one
|
|
543
563
|
// of them wrong:
|
|
544
564
|
// codeCarrying — this segment RUNS a command string it was handed
|
|
@@ -912,6 +932,60 @@ const PACKAGE_RUNNERS = new Set(["npx", "bunx", "pnpx", "dlx", "pnpm", "yarn", "
|
|
|
912
932
|
const RAFTER_PACKAGE = /^(?:@rafter-security\/cli|rafter-cli|rafter)(?:@[\w.^~*-]+)?$/;
|
|
913
933
|
/** Config keys that gate the hook. Namespace, not a leaf — see hook-control. */
|
|
914
934
|
const PROTECTED_CONFIG_KEY = /^(?:agent\.)?(?:hooks|commandpolicy)\b|^agent\.risklevel$/;
|
|
935
|
+
/**
|
|
936
|
+
* sable-lbyp (from rf-ss67) — `rafter agent exec <operand>` RUNS its operand,
|
|
937
|
+
* so a segment whose exec is rafter's own binary is code-carrying: the quoted
|
|
938
|
+
* operand is a command string, not prose, and must reach the patterns.
|
|
939
|
+
*
|
|
940
|
+
* Before this, `rafter agent exec --force "rm -rf /tmp/x"` was the one shape
|
|
941
|
+
* the hook could not see: an unrecognised evaluator with a quoted multi-word
|
|
942
|
+
* argument is data by the sanitizer's rule, so the hook said `low` while exec
|
|
943
|
+
* ran a HIGH-tier command. rf-ss67 closed the bypass at the other end (exec no
|
|
944
|
+
* longer skips approval and only a person at a TTY can grant it); this makes
|
|
945
|
+
* the hook itself classify the operand, so the audit trail and the block land
|
|
946
|
+
* where the agent's tool call is, not two processes later.
|
|
947
|
+
*
|
|
948
|
+
* Resolution is the same as the rf-vnxs disarm check: the segment's resolved
|
|
949
|
+
* exec (wrappers such as `sudo -E`, `env`, `unbuffer` already skipped by the
|
|
950
|
+
* caller), an absolute path (`execName` keeps the basename, so
|
|
951
|
+
* `/usr/local/bin/rafter` is `rafter`), or a package runner
|
|
952
|
+
* (`npx @rafter-security/cli`, `pnpm dlx rafter-cli`, `bunx rafter`).
|
|
953
|
+
*
|
|
954
|
+
* `--dry-run` is the one exemption: exec then prints the classification and
|
|
955
|
+
* runs nothing, and that flow is what the shipped docs tell agents to use to
|
|
956
|
+
* check a command BEFORE running it. Treating its operand as executed would
|
|
957
|
+
* block the very check. A flag an old CLI does not know makes it error out,
|
|
958
|
+
* never execute, so the exemption cannot be abused by version skew.
|
|
959
|
+
*/
|
|
960
|
+
function rafterExecRunsOperand(pieces, execIdx) {
|
|
961
|
+
if (execIdx === -1)
|
|
962
|
+
return false;
|
|
963
|
+
let k = execIdx;
|
|
964
|
+
let exec = execName(pieces[k].text);
|
|
965
|
+
if (pieces[k].quoted)
|
|
966
|
+
return false;
|
|
967
|
+
k++;
|
|
968
|
+
if (PACKAGE_RUNNERS.has(exec)) {
|
|
969
|
+
while (k < pieces.length && !pieces[k].op && (pieces[k].text.startsWith("-") || ["dlx", "exec"].includes(pieces[k].text.toLowerCase())))
|
|
970
|
+
k++;
|
|
971
|
+
if (k >= pieces.length || pieces[k].op || !RAFTER_PACKAGE.test(pieces[k].text.toLowerCase()))
|
|
972
|
+
return false;
|
|
973
|
+
k++;
|
|
974
|
+
exec = "rafter";
|
|
975
|
+
}
|
|
976
|
+
if (!RAFTER_EXECS.has(exec))
|
|
977
|
+
return false;
|
|
978
|
+
const rest = pieces.slice(k).filter((p) => !p.op);
|
|
979
|
+
const args = rest.filter((p) => !p.text.startsWith("-")).map((p) => p.text.toLowerCase());
|
|
980
|
+
if (args[0] !== "agent" || args[1] !== "exec")
|
|
981
|
+
return false;
|
|
982
|
+
// Only a --dry-run before an unquoted `--` is the flag: after it, exec
|
|
983
|
+
// takes every token as part of the command and runs it.
|
|
984
|
+
const end = rest.findIndex((p) => !p.quoted && p.text === "--");
|
|
985
|
+
const flags = end === -1 ? rest : rest.slice(0, end);
|
|
986
|
+
const dryRun = flags.some((p) => !p.quoted && p.text.toLowerCase() === "--dry-run");
|
|
987
|
+
return !dryRun;
|
|
988
|
+
}
|
|
915
989
|
/**
|
|
916
990
|
* True if this statement's argv reconfigures or removes a rafter security
|
|
917
991
|
* control.
|
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.6
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|