@rafter-security/cli 0.9.1 → 0.10.1
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/commands/agent/exec.js +63 -11
- package/dist/commands/agent/init.js +94 -19
- package/dist/commands/agent/scan.js +6 -2
- package/dist/commands/agent/verify.js +128 -6
- package/dist/commands/backend/get.js +9 -4
- package/dist/commands/backend/run.js +3 -4
- package/dist/commands/backend/scan-status.js +211 -26
- package/dist/commands/backend/usage.js +2 -3
- package/dist/commands/issues/from-scan.js +26 -6
- package/dist/commands/issues/from-text.js +1 -1
- package/dist/commands/issues/issue-builder.js +1 -1
- package/dist/commands/mcp/server.js +122 -0
- package/dist/commands/notify.js +2 -3
- package/dist/commands/sites/create.js +29 -0
- package/dist/commands/sites/errors.js +78 -0
- package/dist/commands/sites/get.js +29 -0
- package/dist/commands/sites/index.js +27 -0
- package/dist/commands/sites/list.js +38 -0
- package/dist/commands/sites/scan.js +53 -0
- package/dist/core/risk-rules.js +321 -18
- package/dist/index.js +6 -1
- package/dist/scanners/betterleaks.js +7 -0
- package/dist/utils/api.js +52 -0
- package/dist/utils/env-guard.js +32 -0
- package/package.json +1 -1
- package/resources/rafter-security-skill.md +1 -1
- package/resources/skills/rafter/docs/cli-reference.md +1 -1
- package/resources/skills/rafter/docs/guardrails.md +2 -2
package/dist/utils/api.js
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
|
+
import axios from "axios";
|
|
1
2
|
import { ConfigManager } from "../core/config-manager.js";
|
|
2
3
|
export const API = "https://rafter.so/api/";
|
|
4
|
+
/**
|
|
5
|
+
* sable-2s6p — the HTTP client for every authenticated Rafter API call.
|
|
6
|
+
*
|
|
7
|
+
* `maxRedirects: 0` is the point of it. axios (via follow-redirects) replays
|
|
8
|
+
* request headers on a redirect, and unlike `Authorization` the custom
|
|
9
|
+
* `x-api-key` header is not stripped when the host changes. Since the API base
|
|
10
|
+
* is user-settable (`--rafter-url`, self-hosted installs), a 302 from a
|
|
11
|
+
* misconfigured or hostile endpoint would walk the caller's API key to another
|
|
12
|
+
* host. Nothing in this CLI needs to follow a redirect, so none of them do.
|
|
13
|
+
*
|
|
14
|
+
* Use this for anything that sends `x-api-key`. Plain `axios` is fine for
|
|
15
|
+
* user-supplied webhooks and other unauthenticated calls.
|
|
16
|
+
*/
|
|
17
|
+
export const apiClient = axios.create({
|
|
18
|
+
maxRedirects: 0,
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* A redirect target is attacker-controlled if the endpoint is. Header values
|
|
22
|
+
* cannot contain CR/LF, but ESC is a legal byte, so an unsanitized Location can
|
|
23
|
+
* emit ANSI sequences that rewrite the user's terminal. Strip anything
|
|
24
|
+
* non-printable and cap the length.
|
|
25
|
+
*/
|
|
26
|
+
function safeForTerminal(value) {
|
|
27
|
+
if (typeof value !== "string")
|
|
28
|
+
return "";
|
|
29
|
+
// eslint-disable-next-line no-control-regex
|
|
30
|
+
const printable = value.replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
|
|
31
|
+
return printable.length > 200 ? `${printable.slice(0, 200)}…` : printable;
|
|
32
|
+
}
|
|
33
|
+
// A refused redirect otherwise surfaces as a bare "Request failed with status
|
|
34
|
+
// code 302", which tells the user nothing about why. Name the cause.
|
|
35
|
+
apiClient.interceptors.response.use(undefined, (error) => {
|
|
36
|
+
const status = error?.response?.status;
|
|
37
|
+
if (status >= 300 && status < 400) {
|
|
38
|
+
const target = safeForTerminal(error?.response?.headers?.location) || "another host";
|
|
39
|
+
error.message =
|
|
40
|
+
`The Rafter API redirected to ${target}, and Rafter does not follow redirects ` +
|
|
41
|
+
`on authenticated requests — your API key would be sent to the redirect target. ` +
|
|
42
|
+
`If you are pointing Rafter at a self-hosted instance, use its final URL.`;
|
|
43
|
+
}
|
|
44
|
+
return Promise.reject(error);
|
|
45
|
+
});
|
|
46
|
+
/** Join API with a path segment without producing a double slash, regardless of leading/trailing slashes on either side. */
|
|
47
|
+
export function apiUrl(path) {
|
|
48
|
+
return `${API.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
49
|
+
}
|
|
3
50
|
// Exit codes
|
|
51
|
+
/**
|
|
52
|
+
* Read timeout for short-lived API calls (status polls and the like), in ms.
|
|
53
|
+
* Mirrors the read half of Python's `API_TIMEOUT_SHORT`.
|
|
54
|
+
*/
|
|
55
|
+
export const API_TIMEOUT_SHORT_MS = 30000;
|
|
4
56
|
export const EXIT_SUCCESS = 0;
|
|
5
57
|
export const EXIT_GENERAL_ERROR = 1;
|
|
6
58
|
export const EXIT_SCAN_NOT_FOUND = 2;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security-control env vars must never be settable by a project `.env`.
|
|
3
|
+
*
|
|
4
|
+
* `dotenv.config()` runs at CLI startup (index.ts) and, with no path, loads
|
|
5
|
+
* `$CWD/.env` — which, when rafter runs inside an agent hook on a cloned repo,
|
|
6
|
+
* is a file IN THE UNTRUSTED REPOSITORY. dotenv does not override a variable
|
|
7
|
+
* already present in the real environment, but it DOES introduce one that was
|
|
8
|
+
* unset — so a repo shipping `RAFTER_DISABLE_HOOKS=1` (or any `RAFTER_DISABLE_*`
|
|
9
|
+
* / `RAFTER_HOOK_*` value) could switch off the victim's command policy and
|
|
10
|
+
* secret scanning. That defeats the control whose own contract (hook-control.ts)
|
|
11
|
+
* says the disable signal is honored only from the machine owner's environment.
|
|
12
|
+
*
|
|
13
|
+
* This runs dotenv, then drops any `RAFTER_DISABLE_*` / `RAFTER_HOOK_*` variable
|
|
14
|
+
* that was NOT already set in the real environment before dotenv ran. The
|
|
15
|
+
* owner's real values are preserved untouched; legitimate `.env` keys that do
|
|
16
|
+
* not match those prefixes (RAFTER_API_KEY, RAFTER_GITHUB_TOKEN, …) are
|
|
17
|
+
* unaffected. rf-7dda / sable-nz4y sibling.
|
|
18
|
+
*/
|
|
19
|
+
const PROTECTED_PREFIX = /^RAFTER_(DISABLE_|HOOK_)/;
|
|
20
|
+
export function guardSecurityEnvFromDotenv(applyDotenv, env = process.env) {
|
|
21
|
+
const present = new Set();
|
|
22
|
+
for (const k of Object.keys(env)) {
|
|
23
|
+
if (PROTECTED_PREFIX.test(k))
|
|
24
|
+
present.add(k);
|
|
25
|
+
}
|
|
26
|
+
applyDotenv();
|
|
27
|
+
for (const k of Object.keys(env)) {
|
|
28
|
+
if (PROTECTED_PREFIX.test(k) && !present.has(k)) {
|
|
29
|
+
delete env[k];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
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.
|
|
4
|
+
version: 0.10.1
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|
|
@@ -64,7 +64,7 @@ When: before firing multiple remote scans, or when the user asks about limits.
|
|
|
64
64
|
|
|
65
65
|
Classify and optionally run a shell command through Rafter's risk tiers (critical / high / medium / low).
|
|
66
66
|
|
|
67
|
-
When: any time a destructive-looking command is about to be executed by an agent. Use `--dry-run` to classify without running.
|
|
67
|
+
When: any time a destructive-looking command is about to be executed by an agent. Use `--dry-run` to classify without running: exit 0 = allowed, 1 = blocked, 2 = needs a person's approval. Without `--dry-run`, a command that needs approval is only ever approved by a person at an interactive terminal; from an agent's shell it is denied.
|
|
68
68
|
|
|
69
69
|
Example: `rafter agent exec --dry-run -- rm -rf $WORK_DIR`
|
|
70
70
|
|
|
@@ -10,7 +10,7 @@ Rafter exposes two hook handlers over stdio:
|
|
|
10
10
|
- `rafter hook posttool` — read a JSON event after a tool ran; log to audit trail, optionally rescan written files for secrets.
|
|
11
11
|
|
|
12
12
|
For platforms without hooks, the same classifier is reachable as:
|
|
13
|
-
- `rafter agent exec --dry-run -- <command>` (
|
|
13
|
+
- `rafter agent exec --dry-run -- <command>` (prints the risk tier and runs nothing; exits 0 allowed, 1 blocked, 2 needs a person's approval)
|
|
14
14
|
- `rafter mcp serve` → MCP tool `evaluate_command`
|
|
15
15
|
|
|
16
16
|
## Risk Tiers
|
|
@@ -66,7 +66,7 @@ If the block is a false positive **for this specific context**, the right path i
|
|
|
66
66
|
allow:
|
|
67
67
|
- "^terraform destroy -target=module\\.sandbox"
|
|
68
68
|
```
|
|
69
|
-
2. Or
|
|
69
|
+
2. Or have a person run it: `rafter agent exec -- <command>` prompts for approval only at an interactive terminal and logs the override to the audit trail. There is no acknowledgement flag — `--force` no longer skips the prompt and a piped `yes` is not an approval — because any flag or input an agent can supply is not a person's decision.
|
|
70
70
|
3. Never disable the hook globally to get past one command — that silently drops protection for every future call.
|
|
71
71
|
|
|
72
72
|
## Audit Trail
|