@rafter-security/cli 0.10.1 → 0.10.2
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.
|
@@ -77,6 +77,10 @@ function validateConfig(raw) {
|
|
|
77
77
|
console.error('Warning: config "agent.commandPolicy.requireApproval" must be an array of strings — using default.');
|
|
78
78
|
cp.requireApproval = [...defaults.agent.commandPolicy.requireApproval];
|
|
79
79
|
}
|
|
80
|
+
if (cp.allowProjectOverride !== undefined && typeof cp.allowProjectOverride !== "boolean") {
|
|
81
|
+
console.error('Warning: config "agent.commandPolicy.allowProjectOverride" must be a boolean — ignoring (project policies cannot loosen command policy).');
|
|
82
|
+
delete cp.allowProjectOverride;
|
|
83
|
+
}
|
|
80
84
|
}
|
|
81
85
|
// audit
|
|
82
86
|
const audit = agent.audit;
|
|
@@ -261,6 +265,18 @@ export class ConfigManager {
|
|
|
261
265
|
this.save(config);
|
|
262
266
|
}
|
|
263
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Whether the machine owner has opted out of the project-policy floor.
|
|
270
|
+
*
|
|
271
|
+
* Read from `this.load()` — the GLOBAL config file only. It must never be
|
|
272
|
+
* sourced from the project `.rafter.yml`, because a repo that could set this
|
|
273
|
+
* flag could switch the floor off and the protection would be worth nothing.
|
|
274
|
+
* That asymmetry is the whole point of the setting, so it is read here rather
|
|
275
|
+
* than off the already-merged config.
|
|
276
|
+
*/
|
|
277
|
+
allowsProjectOverride() {
|
|
278
|
+
return this.load().agent?.commandPolicy?.allowProjectOverride === true;
|
|
279
|
+
}
|
|
264
280
|
/**
|
|
265
281
|
* Load config merged with .rafter.yml policy (policy wins)
|
|
266
282
|
*/
|
|
@@ -278,17 +294,10 @@ export class ConfigManager {
|
|
|
278
294
|
if (policy.riskLevel && config.agent) {
|
|
279
295
|
config.agent.riskLevel = policy.riskLevel;
|
|
280
296
|
}
|
|
281
|
-
// Command policy —
|
|
297
|
+
// Command policy — the global config is a FLOOR the project may raise but
|
|
298
|
+
// never lower. See `mergeCommandPolicy` (sable-nz4y).
|
|
282
299
|
if (policy.commandPolicy && config.agent) {
|
|
283
|
-
|
|
284
|
-
config.agent.commandPolicy.mode = policy.commandPolicy.mode;
|
|
285
|
-
}
|
|
286
|
-
if (policy.commandPolicy.blockedPatterns) {
|
|
287
|
-
config.agent.commandPolicy.blockedPatterns = policy.commandPolicy.blockedPatterns;
|
|
288
|
-
}
|
|
289
|
-
if (policy.commandPolicy.requireApproval) {
|
|
290
|
-
config.agent.commandPolicy.requireApproval = policy.commandPolicy.requireApproval;
|
|
291
|
-
}
|
|
300
|
+
mergeCommandPolicy(config.agent.commandPolicy, policy.commandPolicy, this.allowsProjectOverride());
|
|
292
301
|
}
|
|
293
302
|
// Scan settings
|
|
294
303
|
if (policy.scan && config.agent) {
|
|
@@ -390,3 +399,89 @@ export class ConfigManager {
|
|
|
390
399
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
391
400
|
}
|
|
392
401
|
}
|
|
402
|
+
// ---------------------------------------------------------------------------
|
|
403
|
+
// Project-policy floor (sable-nz4y)
|
|
404
|
+
// ---------------------------------------------------------------------------
|
|
405
|
+
//
|
|
406
|
+
// Policy discovery walks up from cwd to the git root, so the `.rafter.yml` this
|
|
407
|
+
// merges is a file IN THE REPOSITORY BEING WORKED ON. rafter ships inside agent
|
|
408
|
+
// pretool hooks, so on an untrusted repo that file is attacker-controlled.
|
|
409
|
+
//
|
|
410
|
+
// It used to REPLACE the machine owner's command policy wholesale: a repo
|
|
411
|
+
// shipping `{ mode: allow-all, blocked_patterns: [], require_approval: [] }`
|
|
412
|
+
// switched off every guardrail below the unconditional critical hard-block —
|
|
413
|
+
// including patterns the owner had explicitly deny-listed.
|
|
414
|
+
//
|
|
415
|
+
// The rule this restores is the one the codebase already states ~20 lines below,
|
|
416
|
+
// for the Plus-approval gate (sable-9ddf): a project policy may turn a gate ON,
|
|
417
|
+
// but must never turn OFF a gate the machine owner set globally. So the global
|
|
418
|
+
// config is a FLOOR:
|
|
419
|
+
//
|
|
420
|
+
// * blockedPatterns / requireApproval — UNION. A project adds rules; removing
|
|
421
|
+
// one the owner set is not expressible.
|
|
422
|
+
// * mode — accepted only when at least as strict as the owner's. A project
|
|
423
|
+
// may tighten `allow-all` to `approve-dangerous`, never the reverse.
|
|
424
|
+
//
|
|
425
|
+
// The owner (never the repo) can opt out with
|
|
426
|
+
// `agent.commandPolicy.allowProjectOverride: true` in the GLOBAL config, which
|
|
427
|
+
// restores the old replace semantics for people who deliberately delegate policy
|
|
428
|
+
// to their projects.
|
|
429
|
+
//
|
|
430
|
+
// Note this does not touch the critical hard-block, which was never reachable
|
|
431
|
+
// from policy: CommandInterceptor.evaluate() returns on `critical` BEFORE any
|
|
432
|
+
// policy is loaded. That property held under every hostile policy tested; this
|
|
433
|
+
// change is about everything *below* critical.
|
|
434
|
+
/**
|
|
435
|
+
* Strictness rank for command-policy modes. Higher is stricter.
|
|
436
|
+
*
|
|
437
|
+
* `approve-dangerous` is the only mode that gates on assessed risk, so it is
|
|
438
|
+
* strictly stronger than the other two. `deny-list` and `allow-all` currently
|
|
439
|
+
* behave identically in the interceptor (both rely solely on the explicit
|
|
440
|
+
* pattern lists, which are checked regardless of mode) — they are ranked apart
|
|
441
|
+
* anyway so that a project moving `allow-all` -> `deny-list` is treated as a
|
|
442
|
+
* tightening rather than a lateral move if their behavior ever diverges.
|
|
443
|
+
*/
|
|
444
|
+
const COMMAND_MODE_STRICTNESS = {
|
|
445
|
+
"allow-all": 0,
|
|
446
|
+
"deny-list": 1,
|
|
447
|
+
"approve-dangerous": 2,
|
|
448
|
+
};
|
|
449
|
+
/** Union preserving order: floor entries first, then project entries not already present. */
|
|
450
|
+
function unionPatterns(floor, project) {
|
|
451
|
+
const seen = new Set(floor);
|
|
452
|
+
return [...floor, ...project.filter((p) => !seen.has(p))];
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Merge a project command policy over the global one under the floor rule.
|
|
456
|
+
*
|
|
457
|
+
* Mutates `target` in place, matching the surrounding merge style. When
|
|
458
|
+
* `allowOverride` is true the pre-sable-nz4y replace semantics are used.
|
|
459
|
+
*/
|
|
460
|
+
export function mergeCommandPolicy(target, project, allowOverride) {
|
|
461
|
+
if (allowOverride) {
|
|
462
|
+
if (project.mode)
|
|
463
|
+
target.mode = project.mode;
|
|
464
|
+
if (project.blockedPatterns)
|
|
465
|
+
target.blockedPatterns = project.blockedPatterns;
|
|
466
|
+
if (project.requireApproval)
|
|
467
|
+
target.requireApproval = project.requireApproval;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (project.mode && project.mode !== target.mode) {
|
|
471
|
+
const projectRank = COMMAND_MODE_STRICTNESS[project.mode];
|
|
472
|
+
const floorRank = COMMAND_MODE_STRICTNESS[target.mode];
|
|
473
|
+
// An unknown mode is not demonstrably at least as strict, so it is refused.
|
|
474
|
+
if (projectRank !== undefined && floorRank !== undefined && projectRank >= floorRank) {
|
|
475
|
+
target.mode = project.mode;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
console.error(`Warning: project policy sets agent.commandPolicy.mode "${project.mode}", which is less strict than "${target.mode}" from your global config — ignoring. Set agent.commandPolicy.allowProjectOverride: true in your global config to allow project policies to loosen command policy.`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (project.blockedPatterns) {
|
|
482
|
+
target.blockedPatterns = unionPatterns(target.blockedPatterns, project.blockedPatterns);
|
|
483
|
+
}
|
|
484
|
+
if (project.requireApproval) {
|
|
485
|
+
target.requireApproval = unionPatterns(target.requireApproval, project.requireApproval);
|
|
486
|
+
}
|
|
487
|
+
}
|
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.2
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|