@rafter-security/cli 0.8.10 → 0.9.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/components.js +58 -2
- package/dist/commands/agent/init.js +101 -5
- package/dist/commands/agent/instruction-block.js +21 -9
- package/dist/commands/agent/status.js +2 -0
- package/dist/commands/agent/verify.js +29 -0
- package/dist/commands/backend/run.js +77 -2
- package/dist/commands/scan/index.js +6 -0
- package/dist/core/command-interceptor.js +28 -41
- package/dist/core/config-manager.js +9 -0
- package/dist/core/pattern-engine.js +33 -2
- package/dist/core/policy-loader.js +9 -0
- package/dist/core/risk-rules.js +408 -28
- package/dist/scanners/secret-patterns.js +21 -0
- package/dist/utils/api.js +3 -0
- package/dist/utils/git.js +63 -4
- package/package.json +6 -2
- package/resources/rafter-security-skill.md +1 -1
- package/resources/skills/rafter/SKILL.md +18 -8
- package/resources/skills/rafter-code-review/SKILL.md +7 -1
- package/resources/skills/rafter-secure-design/SKILL.md +7 -1
package/dist/utils/git.js
CHANGED
|
@@ -19,19 +19,78 @@ export function parseRemote(url) {
|
|
|
19
19
|
const parts = url.split("/");
|
|
20
20
|
return parts.slice(-2).join("/"); // owner/repo
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Map a git remote host to a provider. `github` is the backward-compatible
|
|
24
|
+
* default for any host we don't recognize — a GitHub user's request is
|
|
25
|
+
* unaffected, and unknown self-hosted hosts fall back to the legacy behavior.
|
|
26
|
+
*/
|
|
27
|
+
export function providerForHost(host) {
|
|
28
|
+
host = host.toLowerCase();
|
|
29
|
+
if (host === "github.com")
|
|
30
|
+
return "github";
|
|
31
|
+
if (host === "gitlab.com" || host.endsWith(".gitlab.com"))
|
|
32
|
+
return "gitlab";
|
|
33
|
+
if (host === "bitbucket.org")
|
|
34
|
+
return "bitbucket";
|
|
35
|
+
if (host === "codeberg.org" || host.endsWith(".gitea.io"))
|
|
36
|
+
return "gitea";
|
|
37
|
+
return "github"; // backward-compatible default
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Split a git remote URL into its host + owner/repo slug, handling both
|
|
41
|
+
* `git@host:owner/repo(.git)` (scp-like) and `https://host/owner/repo(.git)`.
|
|
42
|
+
* Returns null when the URL can't be parsed into host + slug.
|
|
43
|
+
*/
|
|
44
|
+
function splitRemote(url) {
|
|
45
|
+
let rest = url.replace(/^(https?:\/\/|git@)/, "").replace(":", "/");
|
|
46
|
+
if (rest.endsWith(".git"))
|
|
47
|
+
rest = rest.slice(0, -4);
|
|
48
|
+
const parts = rest.split("/").filter((p) => p.length > 0);
|
|
49
|
+
if (parts.length < 3)
|
|
50
|
+
return null; // need host + owner + repo
|
|
51
|
+
const host = parts[0];
|
|
52
|
+
const slug = parts.slice(-2).join("/");
|
|
53
|
+
return { host, slug };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Infer the provider and a canonical `https://<host>/<owner>/<repo>` clone URL
|
|
57
|
+
* from a git remote (either scp-like `git@` or `https://` form). Falls back to
|
|
58
|
+
* `{ provider: "github", repoUrl: undefined }` when the URL can't be parsed.
|
|
59
|
+
*/
|
|
60
|
+
export function inferRemote(url) {
|
|
61
|
+
const parts = splitRemote(url);
|
|
62
|
+
if (!parts)
|
|
63
|
+
return { provider: "github" };
|
|
64
|
+
return {
|
|
65
|
+
provider: providerForHost(parts.host),
|
|
66
|
+
repoUrl: `https://${parts.host}/${parts.slug}`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
22
69
|
export function detectRepo(opts) {
|
|
70
|
+
// Both explicit — return them as-is. No provider/repo_url is inferred here;
|
|
71
|
+
// the caller's --provider/--repo-url flags fill that in when needed.
|
|
23
72
|
if (opts.repo && opts.branch)
|
|
24
|
-
return opts;
|
|
73
|
+
return { repo: opts.repo, branch: opts.branch };
|
|
25
74
|
const repoEnv = process.env.GITHUB_REPOSITORY || process.env.CI_REPOSITORY;
|
|
26
75
|
const branchEnv = process.env.GITHUB_REF_NAME || process.env.CI_COMMIT_BRANCH || process.env.CI_BRANCH;
|
|
27
76
|
let repoSlug = opts.repo || repoEnv;
|
|
28
77
|
let branch = opts.branch || branchEnv;
|
|
78
|
+
let provider;
|
|
79
|
+
let repoUrl;
|
|
29
80
|
try {
|
|
30
81
|
if (!repoSlug || !branch) {
|
|
31
82
|
if (git("rev-parse --is-inside-work-tree") !== "true")
|
|
32
83
|
throw new Error("not a repo");
|
|
33
|
-
|
|
34
|
-
|
|
84
|
+
// Read the remote once when we need to detect the slug, and reuse it to
|
|
85
|
+
// infer the provider + canonical clone URL. When repo/branch come from
|
|
86
|
+
// env (CI), we never touch git here — behavior is byte-identical.
|
|
87
|
+
if (!repoSlug) {
|
|
88
|
+
const remoteUrl = git("remote get-url origin");
|
|
89
|
+
repoSlug = parseRemote(remoteUrl);
|
|
90
|
+
const inferred = inferRemote(remoteUrl);
|
|
91
|
+
provider = inferred.provider;
|
|
92
|
+
repoUrl = inferred.repoUrl;
|
|
93
|
+
}
|
|
35
94
|
if (!branch) {
|
|
36
95
|
try {
|
|
37
96
|
branch = safeBranch(git);
|
|
@@ -44,7 +103,7 @@ export function detectRepo(opts) {
|
|
|
44
103
|
if ((!opts.repo || !opts.branch) && !opts.quiet) {
|
|
45
104
|
console.error(`Repo auto-detected: ${repoSlug} @ ${branch} (note: scanning remote)`);
|
|
46
105
|
}
|
|
47
|
-
return { repo: repoSlug, branch };
|
|
106
|
+
return { repo: repoSlug, branch, provider, repo_url: repoUrl };
|
|
48
107
|
}
|
|
49
108
|
catch {
|
|
50
109
|
throw new Error("Could not auto-detect Git repository. Please pass --repo and --branch explicitly.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rafter-security/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
"build": "tsc -p tsconfig.json",
|
|
25
25
|
"prepublishOnly": "pnpm run build",
|
|
26
26
|
"postinstall": "echo '\n Run: rafter agent init --all\n Sets up secret scanning for Claude Code, Codex CLI, and git hooks.\n'",
|
|
27
|
-
"test": "vitest"
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"test:coverage": "vitest run --coverage",
|
|
30
|
+
"clean": "rm -rf dist/ node_modules/.cache/"
|
|
28
31
|
},
|
|
29
32
|
"engines": {
|
|
30
33
|
"node": ">=18"
|
|
@@ -44,6 +47,7 @@
|
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@types/js-yaml": "^4.0.9",
|
|
46
49
|
"@types/node": "^20.11.30",
|
|
50
|
+
"@vitest/coverage-v8": "4.1.0",
|
|
47
51
|
"tsx": "^4.7.0",
|
|
48
52
|
"typescript": "^5.4.5",
|
|
49
53
|
"vitest": "^4.1.0"
|
|
@@ -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.9.1
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: rafter
|
|
3
|
-
description: "Entry point for rafter. Invoke when a sub-skill is unclear, or when the task needs `rafter run` (remote SAST+SCA), `rafter secrets` (local secrets-only), `rafter audit`, policy checks, or command-risk evaluation.
|
|
3
|
+
description: "Entry point for rafter. Invoke when a sub-skill is unclear, or when the task needs `rafter run` (remote SAST+SCA), `rafter secrets` (local secrets-only), `rafter audit`, policy checks, or command-risk evaluation. Scope by security surface, not task label: engage when the diff touches auth, credentials/secrets/tokens, untrusted input, SQL, shell/exec, file paths, deserialization, crypto, network endpoints, data deletion, or dependencies; for research/experimental/local-only code with none of that, a quick surface check is enough. When such surface IS present and no rafter skill or CLI call has been made, invoke this before handing the task off — an un-evaluated \"done\" on genuine security surface is not done."
|
|
4
4
|
version: 0.7.0
|
|
5
5
|
allowed-tools: [Bash, Read]
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Rafter — Security Toolkit for AI Workflows
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## When Rafter applies (and when it doesn't)
|
|
11
|
+
|
|
12
|
+
Rafter is a **surface-driven** gate, not a task-label gate. Read the diff's actual security surface first; let that — not whether the work is called "research" — pick the branch.
|
|
13
|
+
|
|
14
|
+
**Engage fully** (walk the review + run `rafter run`) when the change touches any of: auth / sessions / access control · credentials, secrets, tokens, keys · user-supplied or otherwise untrusted input · SQL or any other query / command construction · shell, `exec`, or subprocess invocation · file paths (read, write, upload, traversal) · deserialization or parsing of untrusted data · crypto primitives · network-facing endpoints or outbound fetchers (SSRF surface) · data deletion or other destructive mutations · dependency, lockfile, or manifest changes.
|
|
15
|
+
|
|
16
|
+
**Back off** when the change touches **none** of those — research / experimental / exploratory / local-only / throwaway code: training scripts, data analysis, plotting, model eval, notebooks, pure computation over trusted local data. A quick surface check is enough; with no security surface, proceed **without** the full `rafter-code-review` + `rafter run`.
|
|
11
17
|
|
|
12
|
-
|
|
18
|
+
**The rule that decides it:** the "research" label buys nothing. Research code that reads a secret, shells out, hits the network, parses untrusted input, or bumps a dependency is on the engage list and gets the full gate. Judge by the surface of the diff, not by what the task is called.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Picking the right tier — DO NOT stop at "local"
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
2. **Remote fast (`rafter run`, default mode)** — SAST + SCA + secrets via the Rafter API. This is the real code-analysis pass: dataflow, taint, known-vulnerable dependencies, crypto misuse, injection sinks. Needs `RAFTER_API_KEY`.
|
|
16
|
-
3. **Remote plus (`rafter run --mode plus`)** — agentic deep-dive: LLM-guided investigation of suspicious patterns the rules engine flags. Slower, higher signal. Code is deleted server-side after the run.
|
|
24
|
+
Three tiers, **not interchangeable**. The local tier is narrow; skipping remote analysis is the #1 way agents under-use rafter.
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
1. **`rafter secrets`** — hardcoded credentials only (regex + betterleaks). Fast, offline, no key. **NOT a code security scan** — it finds no SQL injection, SSRF, auth bugs, insecure deserialization, logic flaws, or dependency vulns. A clean `rafter secrets .` is secret-hygiene, not security review.
|
|
27
|
+
2. **`rafter run`** (default mode) — the real code-analysis pass: SAST + SCA + secrets (dataflow, taint, known-vulnerable deps, crypto misuse, injection sinks). Needs `RAFTER_API_KEY`.
|
|
28
|
+
3. **`rafter run --mode plus`** — agentic deep-dive: LLM-guided investigation of what the rules engine flags. Slower, higher signal; code is deleted server-side after the run. **PAID tier — consumes the user's credits; ask before running it.** If `scan.plus_requires_approval` is set, Plus refuses without `--yes` / `RAFTER_CONFIRM=1`.
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
**Default for a security-relevant task: `rafter run`.** Fall back to `rafter secrets` only when no API key is available — and say so explicitly; don't claim the code was "scanned" without qualification. Deterministic findings, stable exit codes and JSON shapes — safe to chain in CI and in agent loops.
|
|
21
31
|
|
|
22
32
|
---
|
|
23
33
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: rafter-code-review
|
|
3
|
-
description: "REQUIRED before declaring a task done when the diff touches user input, SQL, shell, auth, credentials, file paths, serialization, or dependency surface. Walks OWASP/ASVS/MITRE questions the compiler and the test suite won't catch. Pair with `rafter run` on the same diff.
|
|
3
|
+
description: "REQUIRED before declaring a task done when the diff touches user input, SQL, shell, auth, credentials, file paths, serialization, crypto, network endpoints, data deletion, or dependency surface. Judge by that surface, not the task label — research/experimental/local-only code with none of it can skip this. Walks OWASP/ASVS/MITRE questions the compiler and the test suite won't catch. Pair with `rafter run` on the same diff. When the diff has that surface, marking it complete without both has been under-delivered — do not claim done."
|
|
4
4
|
version: 0.7.0
|
|
5
5
|
allowed-tools: [Bash, Read, Glob, Grep]
|
|
6
6
|
---
|
|
@@ -11,6 +11,12 @@ A reviewer's skill, not an audit generator. Each sub-doc is a set of **questions
|
|
|
11
11
|
|
|
12
12
|
> Pair with the `rafter` skill (detection: `rafter scan`, `rafter run`) and `rafter-secure-design` (prevention: design-phase walks). This skill is the middle stage — review before merge.
|
|
13
13
|
|
|
14
|
+
## When this applies (and when it doesn't)
|
|
15
|
+
|
|
16
|
+
Scoped to the **security surface of the diff**, not the task's label. Walk it fully when the change touches: user / untrusted input, SQL or query building, shell / `exec` / subprocess, auth or access control, credentials / secrets / tokens, file paths or uploads, (de)serialization, crypto, network-facing endpoints or outbound fetchers, data deletion, or dependency / manifest changes.
|
|
17
|
+
|
|
18
|
+
If **none** of those are present — research / experimental / exploratory / local-only / throwaway code such as training scripts, data analysis, plotting, model eval, notebooks, or pure computation over trusted local data — a quick surface check is enough; you don't need to walk the full review or pair `rafter run`. But the check is the surface, not the label: research code that reads a secret, shells out, hits the network, or parses untrusted bytes is back on the engage list and gets the full walk.
|
|
19
|
+
|
|
14
20
|
## How to use this skill
|
|
15
21
|
|
|
16
22
|
1. Identify the category of code in front of you (below).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: rafter-secure-design
|
|
3
|
-
description: "REQUIRED before writing code for any feature touching auth, payments, credentials, tokens, sessions, file upload, user data, or data deletion. Invoke it, record answers inline in the design doc or PR description, then write the code. Skipping this is how auth bypass, token leakage, and delete-the-wrong-record bugs ship. If the feature touches any of those surfaces and this hasn't run, the design is incomplete — do not proceed to implementation."
|
|
3
|
+
description: "REQUIRED before writing code for any feature touching auth, payments, credentials, tokens, sessions, file upload, user data, untrusted input, deserialization, network endpoints, or data deletion. Scope by that surface, not the task label — a research/experimental/local-only feature with none of it doesn't need this. Invoke it, record answers inline in the design doc or PR description, then write the code. Skipping this is how auth bypass, token leakage, and delete-the-wrong-record bugs ship. If the feature touches any of those surfaces and this hasn't run, the design is incomplete — do not proceed to implementation."
|
|
4
4
|
version: 0.1.0
|
|
5
5
|
allowed-tools: [Read, Glob, Grep]
|
|
6
6
|
---
|
|
@@ -11,6 +11,12 @@ A designer's skill, not a scanner. The goal is to catch the flaw in the whiteboa
|
|
|
11
11
|
|
|
12
12
|
> Pair with `rafter-code-review` (structured review *during* PR) and the `rafter` skill (automated detection of what slipped through). This skill is the earliest stage — prevention before the code exists.
|
|
13
13
|
|
|
14
|
+
## When this applies (and when it doesn't)
|
|
15
|
+
|
|
16
|
+
Engage this design walk when the feature you're about to build touches a real security surface: auth or access control, credentials / secrets / tokens / sessions, user or untrusted input, SQL or query construction, shell / `exec`, file paths or uploads, (de)serialization, crypto, network-facing endpoints or outbound fetchers, data deletion, or new dependencies.
|
|
17
|
+
|
|
18
|
+
If the thing you're designing has **none** of that — a research / experimental / local-only / throwaway piece such as a training script, analysis pipeline, plot, model-eval harness, notebook, or pure computation over trusted local data — a quick surface check is enough and you can proceed to implementation without the full walk. Judge by the surface, not by whether the work is called "research": a research feature that stores user data, handles a token, or opens a network endpoint is back on the engage list.
|
|
19
|
+
|
|
14
20
|
## How to use this skill
|
|
15
21
|
|
|
16
22
|
1. Identify what's being designed (below). If multiple apply, walk them in the order listed — `threat-modeling` last, as a capstone.
|