@myckasp/agent-permit 0.0.0-stage → 0.1.3

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/src/html.js ADDED
@@ -0,0 +1,300 @@
1
+ import { CAPABILITY_LABELS, SEVERITY_RANK } from "./rules.js";
2
+ import { GRADE_COLORS } from "./report.js";
3
+
4
+ const ESCAPES = {
5
+ "&": "&",
6
+ "<": "&lt;",
7
+ ">": "&gt;",
8
+ '"': "&quot;",
9
+ "'": "&#39;",
10
+ };
11
+
12
+ function esc(value) {
13
+ return String(value).replace(/[&<>"']/g, (char) => ESCAPES[char]);
14
+ }
15
+
16
+ export function renderHtml(report) {
17
+ const accent = GRADE_COLORS[report.grade] ?? "#ff5f6d";
18
+ const findings = [...report.findings].sort(
19
+ (a, b) =>
20
+ SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] ||
21
+ a.file.localeCompare(b.file) ||
22
+ a.line - b.line,
23
+ );
24
+ const generated = new Date().toISOString().slice(0, 10);
25
+
26
+ const capabilityChips = report.capabilities
27
+ .map(
28
+ (capability) => `
29
+ <span class="chip chip-${esc(capability.severity)}">
30
+ ${esc(CAPABILITY_LABELS[capability.name] ?? capability.name)}
31
+ <b>${capability.count}</b>
32
+ </span>`,
33
+ )
34
+ .join("");
35
+
36
+ const findingRows = findings
37
+ .map(
38
+ (finding) => `
39
+ <li class="finding">
40
+ <div class="finding-head">
41
+ <span class="sev sev-${esc(finding.severity)}">${esc(finding.severity)}</span>
42
+ <span class="finding-title">${esc(finding.title)}</span>
43
+ <code class="loc">${esc(finding.file)}:${finding.line}</code>
44
+ </div>
45
+ <pre class="snippet">${esc(finding.snippet)}</pre>
46
+ <p class="why">${esc(finding.why)}</p>
47
+ <p class="fix"><span>fix</span> ${esc(finding.fix)}</p>
48
+ </li>`,
49
+ )
50
+ .join("");
51
+
52
+ return `<!doctype html>
53
+ <html lang="en">
54
+ <head>
55
+ <meta charset="utf-8">
56
+ <meta name="viewport" content="width=device-width, initial-scale=1">
57
+ <title>agent-permit · ${esc(report.grade)} · ${esc(report.target)}</title>
58
+ <style>
59
+ :root {
60
+ --bg: #080a10;
61
+ --card: #10141d;
62
+ --line: #232a38;
63
+ --text: #e8ecf4;
64
+ --muted: #8b94a7;
65
+ --accent: ${accent};
66
+ --critical: #ff5f6d;
67
+ --high: #ff9f45;
68
+ --medium: #ffcc4d;
69
+ --low: #8b94a7;
70
+ }
71
+ * { box-sizing: border-box; }
72
+ body {
73
+ margin: 0;
74
+ padding: 48px 20px;
75
+ background:
76
+ radial-gradient(900px 420px at 12% -8%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
77
+ var(--bg);
78
+ color: var(--text);
79
+ font: 15px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
80
+ }
81
+ .card {
82
+ width: 100%;
83
+ max-width: 940px;
84
+ margin: 0 auto;
85
+ background: linear-gradient(180deg, #121722 0%, var(--card) 100%);
86
+ border: 1px solid var(--line);
87
+ border-radius: 18px;
88
+ overflow: hidden;
89
+ box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
90
+ }
91
+ header {
92
+ display: flex;
93
+ justify-content: space-between;
94
+ gap: 16px;
95
+ padding: 18px 24px;
96
+ border-bottom: 1px solid var(--line);
97
+ font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
98
+ letter-spacing: .08em;
99
+ text-transform: uppercase;
100
+ color: var(--muted);
101
+ }
102
+ header b { color: var(--accent); letter-spacing: .12em; }
103
+ header a { color: inherit; text-decoration: none; }
104
+ header a:hover { color: var(--text); }
105
+ .hero { display: grid; grid-template-columns: 172px 1fr; gap: 24px; padding: 30px 24px 24px; }
106
+ .grade {
107
+ display: flex;
108
+ flex-direction: column;
109
+ align-items: center;
110
+ justify-content: center;
111
+ border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
112
+ background: color-mix(in srgb, var(--accent) 9%, transparent);
113
+ border-radius: 14px;
114
+ padding: 18px 10px;
115
+ }
116
+ .grade-letter {
117
+ font: 800 92px/.9 ui-sans-serif, -apple-system, "Segoe UI", sans-serif;
118
+ color: var(--accent);
119
+ letter-spacing: -.04em;
120
+ }
121
+ .grade-score { margin-top: 8px; font: 600 13px ui-monospace, Consolas, monospace; color: var(--muted); }
122
+ .grade-score b { color: var(--text); font-size: 18px; }
123
+ h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.02em; line-height: 1.2; }
124
+ .verdict { margin: 0 0 16px; color: var(--text); font-size: 16px; }
125
+ .target {
126
+ margin: 0 0 18px;
127
+ padding: 8px 10px;
128
+ background: #0a0d14;
129
+ border: 1px solid var(--line);
130
+ border-radius: 8px;
131
+ color: var(--muted);
132
+ font: 12px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
133
+ overflow-wrap: anywhere;
134
+ }
135
+ .chips { display: flex; flex-wrap: wrap; gap: 8px; }
136
+ .chip {
137
+ display: inline-flex;
138
+ align-items: center;
139
+ gap: 7px;
140
+ padding: 5px 10px;
141
+ border-radius: 999px;
142
+ border: 1px solid var(--line);
143
+ background: #0b0f17;
144
+ font-size: 12.5px;
145
+ color: var(--text);
146
+ }
147
+ .chip b { font: 700 11px ui-monospace, Consolas, monospace; color: var(--muted); }
148
+ .chip-critical { border-color: color-mix(in srgb, var(--critical) 55%, var(--line)); }
149
+ .chip-high { border-color: color-mix(in srgb, var(--high) 55%, var(--line)); }
150
+ .chip-medium { border-color: color-mix(in srgb, var(--medium) 45%, var(--line)); }
151
+ .counts {
152
+ display: grid;
153
+ grid-template-columns: repeat(4, 1fr);
154
+ gap: 10px;
155
+ padding: 0 24px 24px;
156
+ }
157
+ .count {
158
+ border: 1px solid var(--line);
159
+ border-radius: 10px;
160
+ padding: 12px 14px;
161
+ background: #0b0f17;
162
+ }
163
+ .count span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
164
+ .count b { font-size: 22px; font-weight: 700; }
165
+ .count-critical b { color: var(--critical); }
166
+ .count-high b { color: var(--high); }
167
+ .count-medium b { color: var(--medium); }
168
+ .count-low b { color: var(--low); }
169
+ .findings { border-top: 1px solid var(--line); padding: 22px 24px 8px; }
170
+ .findings h2 {
171
+ margin: 0 0 4px;
172
+ font: 12px ui-monospace, Consolas, monospace;
173
+ letter-spacing: .14em;
174
+ text-transform: uppercase;
175
+ color: var(--muted);
176
+ }
177
+ ul { list-style: none; margin: 0; padding: 0; }
178
+ .finding { padding: 16px 0; border-bottom: 1px solid var(--line); }
179
+ .finding:last-child { border-bottom: 0; }
180
+ .finding-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
181
+ .finding-title { font-weight: 650; }
182
+ .loc { margin-left: auto; color: var(--muted); font: 11.5px ui-monospace, Consolas, monospace; }
183
+ .sev {
184
+ padding: 2px 6px;
185
+ border-radius: 4px;
186
+ font: 700 10px ui-monospace, Consolas, monospace;
187
+ letter-spacing: .08em;
188
+ text-transform: uppercase;
189
+ background: #1a1f2b;
190
+ color: var(--muted);
191
+ }
192
+ .sev-critical { background: color-mix(in srgb, var(--critical) 16%, #1a1f2b); color: var(--critical); }
193
+ .sev-high { background: color-mix(in srgb, var(--high) 14%, #1a1f2b); color: var(--high); }
194
+ .sev-medium { background: color-mix(in srgb, var(--medium) 12%, #1a1f2b); color: var(--medium); }
195
+ .snippet {
196
+ margin: 9px 0 8px;
197
+ padding: 10px 12px;
198
+ background: #070a10;
199
+ border: 1px solid var(--line);
200
+ border-radius: 8px;
201
+ color: #c9d3e6;
202
+ font: 12.5px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
203
+ white-space: pre-wrap;
204
+ overflow-wrap: anywhere;
205
+ }
206
+ .why { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
207
+ .fix { margin: 0; font-size: 13px; }
208
+ .fix span {
209
+ margin-right: 6px;
210
+ color: var(--accent);
211
+ font: 700 10px ui-monospace, Consolas, monospace;
212
+ letter-spacing: .1em;
213
+ text-transform: uppercase;
214
+ }
215
+ footer {
216
+ display: flex;
217
+ justify-content: space-between;
218
+ gap: 14px;
219
+ flex-wrap: wrap;
220
+ padding: 16px 24px 20px;
221
+ border-top: 1px solid var(--line);
222
+ color: var(--muted);
223
+ font-size: 12px;
224
+ }
225
+ footer code { color: #aab4c8; font-family: ui-monospace, Consolas, monospace; }
226
+ @media (max-width: 620px) {
227
+ body { padding: 20px 12px; }
228
+ .hero { grid-template-columns: 1fr; }
229
+ .grade { flex-direction: row; gap: 14px; padding: 12px; }
230
+ .grade-letter { font-size: 54px; }
231
+ .counts { grid-template-columns: repeat(2, 1fr); }
232
+ .loc { margin-left: 0; }
233
+ }
234
+ </style>
235
+ </head>
236
+ <body>
237
+ <main class="card">
238
+ <header>
239
+ <a href="https://github.com/MyckasP/agent-permit">agent-permit <b>receipt</b></a>
240
+ <span>${esc(generated)}</span>
241
+ </header>
242
+ <section class="hero">
243
+ <div class="grade">
244
+ <div class="grade-letter">${esc(report.grade)}</div>
245
+ <div class="grade-score"><b>${report.score}</b>/100</div>
246
+ </div>
247
+ <div>
248
+ <h1>${esc(report.verdict)}</h1>
249
+ <p class="verdict">Static capability review of ${report.files.scanned} files. Nothing was executed.</p>
250
+ <p class="target">${esc(report.target)}</p>
251
+ <div class="chips">${capabilityChips || '<span class="chip chip-A">no capabilities matched</span>'}</div>
252
+ </div>
253
+ </section>
254
+ <section class="counts">
255
+ <div class="count count-critical"><span>critical</span><b>${report.counts.critical}</b></div>
256
+ <div class="count count-high"><span>high</span><b>${report.counts.high}</b></div>
257
+ <div class="count count-medium"><span>medium</span><b>${report.counts.medium}</b></div>
258
+ <div class="count count-low"><span>low</span><b>${report.counts.low}</b></div>
259
+ </section>
260
+ <section class="findings">
261
+ <h2>Findings (${findings.length})</h2>
262
+ <ul>${findingRows || "<li class=\"finding\"><p class=\"why\">Nothing matched the rule set.</p></li>"}</ul>
263
+ </section>
264
+ <footer>
265
+ <span>Read the source. This is a static review, not a sandbox.</span>
266
+ <code>npx @myckasp/agent-permit ${esc(report.target)}</code>
267
+ </footer>
268
+ </main>
269
+ </body>
270
+ </html>
271
+ `;
272
+ }
273
+
274
+ export function renderBadge(report) {
275
+ const accent = GRADE_COLORS[report.grade] ?? "#ff5f6d";
276
+ const label = "agent-permit";
277
+ const value = `${report.grade} ${report.score}`;
278
+ const labelWidth = 104;
279
+ const valueWidth = 52;
280
+ const width = labelWidth + valueWidth;
281
+
282
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="28" role="img" aria-label="${label}: ${value}">
283
+ <title>${label}: ${value}</title>
284
+ <linearGradient id="s" x2="0" y2="100%">
285
+ <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
286
+ <stop offset="1" stop-opacity=".1"/>
287
+ </linearGradient>
288
+ <clipPath id="r"><rect width="${width}" height="28" rx="5" fill="#fff"/></clipPath>
289
+ <g clip-path="url(#r)">
290
+ <rect width="${labelWidth}" height="28" fill="#10141d"/>
291
+ <rect x="${labelWidth}" width="${valueWidth}" height="28" fill="${accent}"/>
292
+ <rect width="${width}" height="28" fill="url(#s)"/>
293
+ </g>
294
+ <g fill="#e8ecf4" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
295
+ <text x="${labelWidth / 2}" y="18">${label}</text>
296
+ <text x="${labelWidth + valueWidth / 2}" y="18" fill="#0b0e14" font-weight="bold">${value}</text>
297
+ </g>
298
+ </svg>
299
+ `;
300
+ }
package/src/report.js ADDED
@@ -0,0 +1,172 @@
1
+ import { SEVERITY_WEIGHT, SEVERITY_RANK, CAPABILITY_LABELS } from "./rules.js";
2
+
3
+ export const GRADE_COLORS = {
4
+ A: "#3ddc97",
5
+ B: "#9be15d",
6
+ C: "#ffcc4d",
7
+ D: "#ff9f45",
8
+ F: "#ff5f6d",
9
+ };
10
+
11
+ export const VERDICTS = {
12
+ A: "No risky capabilities found. Read the source anyway.",
13
+ B: "Mostly harmless. Skim the flagged lines before you install.",
14
+ C: "Review the flagged lines before you install this.",
15
+ D: "High risk. Only run this in a sandbox with no credentials.",
16
+ F: "Do not install this blindly. Treat it as untrusted code.",
17
+ };
18
+
19
+ const GRADE_ORDER = ["A", "B", "C", "D", "F"];
20
+ const GRADE_RANK = Object.fromEntries(GRADE_ORDER.map((grade, index) => [grade, index]));
21
+ const GRADE_CEILING = { A: 100, B: 89, C: 79, D: 69, F: 39 };
22
+
23
+ function gradeFor(score) {
24
+ if (score >= 90) return "A";
25
+ if (score >= 80) return "B";
26
+ if (score >= 70) return "C";
27
+ if (score >= 55) return "D";
28
+ return "F";
29
+ }
30
+
31
+ export function summarize(findings) {
32
+ const counts = { critical: 0, high: 0, medium: 0, low: 0 };
33
+ const byRule = new Map();
34
+
35
+ for (const finding of findings) {
36
+ counts[finding.severity] += 1;
37
+ const entry = byRule.get(finding.ruleId) ?? {
38
+ severity: finding.severity,
39
+ files: new Set(),
40
+ };
41
+ entry.files.add(finding.file);
42
+ byRule.set(finding.ruleId, entry);
43
+ }
44
+
45
+ let penalty = 0;
46
+ for (const entry of byRule.values()) {
47
+ const weight = SEVERITY_WEIGHT[entry.severity] ?? 0;
48
+ const spread = Math.min(0.5, (entry.files.size - 1) * 0.15);
49
+ penalty += weight * (1 + spread);
50
+ }
51
+
52
+ let score = Math.max(0, Math.min(100, Math.round(100 - penalty)));
53
+ let grade = gradeFor(score);
54
+
55
+ // A grade never claims "nothing risky" while something matched. A single
56
+ // critical capability is never a B; two are never survivable.
57
+ const cap =
58
+ counts.critical >= 2
59
+ ? "F"
60
+ : counts.critical === 1
61
+ ? "D"
62
+ : counts.high > 0
63
+ ? "C"
64
+ : counts.medium > 0 || counts.low > 0
65
+ ? "B"
66
+ : "A";
67
+ if (GRADE_RANK[cap] > GRADE_RANK[grade]) {
68
+ grade = cap;
69
+ score = Math.min(score, GRADE_CEILING[grade]);
70
+ }
71
+
72
+ return {
73
+ score,
74
+ grade,
75
+ counts,
76
+ verdict: VERDICTS[grade],
77
+ };
78
+ }
79
+
80
+ function paint(text, code, enabled) {
81
+ return enabled ? `\u001b[${code}m${text}\u001b[0m` : text;
82
+ }
83
+
84
+ const SEVERITY_COLOR = {
85
+ critical: "41;97",
86
+ high: "31",
87
+ medium: "33",
88
+ low: "90",
89
+ };
90
+
91
+ const SEVERITY_LABEL = {
92
+ critical: "CRIT",
93
+ high: "HIGH",
94
+ medium: "MED",
95
+ low: "LOW",
96
+ };
97
+
98
+ const GRADE_COLOR_ANSI = {
99
+ A: "32",
100
+ B: "32",
101
+ C: "33",
102
+ D: "33",
103
+ F: "31",
104
+ };
105
+
106
+ function wrapWords(words, width) {
107
+ const lines = [];
108
+ let current = "";
109
+ for (const word of words) {
110
+ const candidate = current ? `${current} · ${word}` : word;
111
+ if (candidate.length > width && current) {
112
+ lines.push(current);
113
+ current = word;
114
+ } else {
115
+ current = candidate;
116
+ }
117
+ }
118
+ if (current) lines.push(current);
119
+ return lines;
120
+ }
121
+
122
+ export function renderTerminal(report, options = {}) {
123
+ const color = options.color === true;
124
+ const max = options.max ?? 8;
125
+ const dim = (text) => paint(text, "2", color);
126
+ const bold = (text) => paint(text, "1", color);
127
+ const out = [];
128
+
129
+ out.push("");
130
+ out.push(` ${bold("agent-permit")} ${dim(`v${report.version}`)} ${dim("· static capability review")}`);
131
+ out.push("");
132
+ out.push(` ${dim("target ")} ${report.target}`);
133
+ out.push(` ${dim("scanned")} ${report.files.scanned} files ${dim("·")} ${report.files.skipped} skipped`);
134
+ out.push("");
135
+
136
+ const grade = paint(report.grade.padEnd(2), GRADE_COLOR_ANSI[report.grade], color);
137
+ out.push(` ${bold(grade)} ${bold(`${report.score}/100`)} ${report.verdict}`);
138
+ out.push("");
139
+
140
+ if (report.capabilities.length > 0) {
141
+ const labels = report.capabilities.map(
142
+ (capability) => CAPABILITY_LABELS[capability.name] ?? capability.name,
143
+ );
144
+ const lines = wrapWords(labels, 64);
145
+ out.push(` ${dim("capabilities")} ${lines[0]}`);
146
+ for (const line of lines.slice(1)) out.push(` ${line}`);
147
+ out.push("");
148
+ }
149
+
150
+ const findings = report.findings;
151
+ const shown = findings.slice(0, max);
152
+ out.push(` ${bold("findings")} ${dim(`(${findings.length})`)}`);
153
+ if (shown.length === 0) {
154
+ out.push(` ${dim("nothing matched the rule set")}`);
155
+ }
156
+ for (const finding of shown) {
157
+ const tag = SEVERITY_LABEL[finding.severity].padEnd(6);
158
+ out.push("");
159
+ out.push(` ${paint(tag, SEVERITY_COLOR[finding.severity], color)}${finding.title}`);
160
+ out.push(` ${dim(`${finding.file}:${finding.line}`)}`);
161
+ out.push(` ${finding.snippet}`);
162
+ }
163
+ if (findings.length > shown.length) {
164
+ out.push("");
165
+ out.push(` ${dim(`+${findings.length - shown.length} more, use --max to show all`)}`);
166
+ }
167
+
168
+ out.push("");
169
+ out.push(` ${dim("static review: files were read, never executed. not a sandbox.")}`);
170
+ out.push("");
171
+ return out.join("\n");
172
+ }
package/src/rules.js ADDED
@@ -0,0 +1,199 @@
1
+ // Every rule answers one question: what could this file make my machine do?
2
+ // Rules are line-based on purpose: a finding points at a line you can read.
3
+ // None of these are proof of malice. They are capabilities, ranked by blast radius.
4
+
5
+ export const SEVERITY_WEIGHT = {
6
+ critical: 26,
7
+ high: 14,
8
+ medium: 6,
9
+ low: 2,
10
+ };
11
+
12
+ export const SEVERITY_RANK = {
13
+ critical: 0,
14
+ high: 1,
15
+ medium: 2,
16
+ low: 3,
17
+ };
18
+
19
+ export const CAPABILITY_LABELS = {
20
+ exec: "runs code",
21
+ network: "uses the network",
22
+ write: "writes files",
23
+ delete: "deletes data",
24
+ secrets: "reads credentials",
25
+ install: "installs on setup",
26
+ obfuscation: "hides what it does",
27
+ instructions: "manipulates the agent",
28
+ exfiltration: "sends data out",
29
+ };
30
+
31
+ const CODE_EXTENSIONS = new Set([
32
+ ".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx",
33
+ ".py", ".sh", ".bash", ".zsh", ".ps1", ".bat", ".cmd",
34
+ ".rb", ".go", ".rs", ".php",
35
+ ]);
36
+
37
+ export function isCodeFile(file) {
38
+ const dot = file.lastIndexOf(".");
39
+ return dot !== -1 && CODE_EXTENSIONS.has(file.slice(dot).toLowerCase());
40
+ }
41
+
42
+ export const RULES = [
43
+ {
44
+ id: "remote-code-execution",
45
+ title: "Downloads and runs remote code",
46
+ severity: "critical",
47
+ capability: "exec",
48
+ re: /(?:curl|wget|Invoke-WebRequest|\biwr\b)[^\n|]{0,140}\|\s*(?:sudo\s+)?(?:bash|sh|zsh|python3?|node)\b|\b(?:iex|Invoke-Expression)\b[^\n]{0,80}(?:DownloadString|Invoke-WebRequest)/i,
49
+ why: "The file fetches a script from the network and executes it. Whatever is served at that URL runs with your permissions, and it can change after this review.",
50
+ fix: "Pin a version, verify a SHA-256 checksum, or vendor the script into the repo.",
51
+ },
52
+ {
53
+ id: "shell-execution",
54
+ title: "Runs shell commands",
55
+ severity: "high",
56
+ capability: "exec",
57
+ re: /\bchild_process\b|\bexecSync\b|\bexecFileSync\b|\bspawnSync\b|\bspawn\s*\(|\bexec\s*\(|\bsystem\s*\(|\bsubprocess\.(?:run|call|Popen|check_output|check_call)\b|\bos\.(?:system|popen|exec[lv]p?e?)\b|Runtime\.getRuntime\(\)\.exec|\bStart-Process\b|\bInvoke-Expression\b/i,
58
+ why: "Executes commands on your machine. A file with this capability can do anything your user account can do.",
59
+ fix: "Read every command it builds, or run it in a container with no secrets mounted.",
60
+ },
61
+ {
62
+ id: "destructive-delete",
63
+ title: "Deletes files or directories",
64
+ severity: "high",
65
+ capability: "delete",
66
+ re: /\brm\s+-(?:[a-z]*r[a-z]*f|[a-z]*f[a-z]*r)[a-z]*\b|shutil\.rmtree|\bRemove-Item\b[^\n]{0,60}-Recurse|\brd\s+\/s\b|\bdel\s+\/f\b/i,
67
+ why: "Recursive deletion does not ask twice. A wrong path or an unresolved variable can wipe more than intended.",
68
+ fix: "Dry-run first, print the resolved path, and prefer moving to trash over removing.",
69
+ },
70
+ {
71
+ id: "env-access",
72
+ title: "Reads environment variables",
73
+ severity: "medium",
74
+ capability: "secrets",
75
+ re: /\bprocess\.env\b|\bos\.environ\b|\bgetenv\s*\(|\bGetEnvironmentVariable\b|\$env:[A-Za-z_]+/i,
76
+ why: "Environment variables are where API keys and tokens usually live. Reading them is not malicious, but this file can see your credentials.",
77
+ fix: "Run it with a scrubbed environment, or pass only the one variable it needs.",
78
+ },
79
+ {
80
+ id: "credential-harvest",
81
+ title: "Touches credential stores",
82
+ severity: "critical",
83
+ capability: "secrets",
84
+ re: /id_rsa|id_ed25519|\.ssh[\\/](?:id_|config|known_hosts)|\.aws[\\/]credentials|\.npmrc\b|Login Data|wallet\.dat|MetaMask|security find-generic-password|\bcredentials\.json\b/i,
85
+ why: "Points at SSH keys, cloud credentials, browser profiles or wallets. Legitimate tools rarely need these paths.",
86
+ fix: "Do not run it with access to these files. Check every line that references them.",
87
+ },
88
+ {
89
+ id: "network-access",
90
+ title: "Makes network requests",
91
+ severity: "medium",
92
+ capability: "network",
93
+ only: isCodeFile,
94
+ re: /\bfetch\s*\(|\baxios\b|\brequests\.(?:get|post|put|patch)\b|\burllib\b|\bhttp\.request\b|\bhttps?:\/\//i,
95
+ why: "Can send data off this machine or pull in new instructions at runtime.",
96
+ fix: "Check the endpoints. Block egress if you only need the tool locally.",
97
+ },
98
+ {
99
+ id: "file-write",
100
+ title: "Writes files",
101
+ severity: "medium",
102
+ capability: "write",
103
+ re: /\bfs\.(?:writeFile|appendFile|mkdir|rename|copyFile|cp)\b|\bwriteFileSync\b|\bopen\s*\([^)]*['"][wa]b?['"]|\bWriteAllText\b|\bos\.WriteFile\b|\bshutil\.(?:copy|move)\b/i,
104
+ why: "Modifies files on disk. That includes config files that other tools trust.",
105
+ fix: "Run it in a scratch directory and diff what it changed.",
106
+ },
107
+ {
108
+ id: "install-hook",
109
+ title: "Runs commands on install",
110
+ severity: "high",
111
+ capability: "install",
112
+ special: "install-hook",
113
+ why: "preinstall/install/postinstall scripts run automatically the moment someone installs the package, often before any code review.",
114
+ fix: "Install with --ignore-scripts, then read what the hook does.",
115
+ },
116
+ {
117
+ id: "package-install",
118
+ title: "Installs extra packages",
119
+ severity: "low",
120
+ capability: "install",
121
+ re: /\b(?:npm|pnpm|yarn|bun)\s+(?:i|install|add)\s+-g\b|\bpip3?\s+install\b|\bbrew\s+install\b|\bchoco\s+install\b|\bwinget\s+install\b|\bcargo\s+install\b/i,
122
+ why: "Pulls in code you did not review, at whatever version is current.",
123
+ fix: "Pin versions and install into a project-local environment.",
124
+ },
125
+ {
126
+ id: "mcp-unpinned-server",
127
+ title: "Runs an unpinned MCP server",
128
+ severity: "high",
129
+ capability: "install",
130
+ special: "mcp",
131
+ why: "The config launches a server that is fetched from the network on every start. Without a pinned version, the code can change between reviews.",
132
+ fix: "Pin the exact version, or point the config at a local checkout you have read.",
133
+ },
134
+ {
135
+ id: "mcp-server-command",
136
+ title: "Launches a local MCP server",
137
+ severity: "medium",
138
+ capability: "exec",
139
+ special: "mcp",
140
+ why: "Starting an MCP server runs a local process with your permissions. Know which executable this is.",
141
+ fix: "Check the command and args, and keep the server on a pinned version.",
142
+ },
143
+ {
144
+ id: "mcp-remote-server",
145
+ title: "Connects to a remote MCP server",
146
+ severity: "high",
147
+ capability: "network",
148
+ special: "mcp",
149
+ why: "The server is hosted elsewhere, so its behaviour can change without any local file changing. It also receives every tool call you send it.",
150
+ fix: "Only connect to servers you trust. Prefer a local, pinned server for sensitive work.",
151
+ },
152
+ {
153
+ id: "dynamic-eval",
154
+ title: "Builds code at runtime",
155
+ severity: "high",
156
+ capability: "obfuscation",
157
+ re: /\beval\s*\(|\bnew\s+Function\s*\(|\batob\s*\(|base64\s+(?:-d|--decode)|\bpickle\.loads\b|\bmarshal\.loads\b|\bvm\.runIn/i,
158
+ why: "Decodes or evaluates code that is not visible in the source you are reading. This is how hidden payloads get in.",
159
+ fix: "Find the decoded payload and read it before running anything.",
160
+ },
161
+ {
162
+ id: "encoded-blob",
163
+ title: "Contains a large encoded blob",
164
+ severity: "low",
165
+ capability: "obfuscation",
166
+ special: "encoded-blob",
167
+ why: "Long base64 strings can hide executables, prompts or configuration that a text review will not show.",
168
+ fix: "Decode it (base64 -d) and inspect the result.",
169
+ },
170
+ {
171
+ id: "prompt-override",
172
+ title: "Manipulates the agent's instructions",
173
+ severity: "high",
174
+ capability: "instructions",
175
+ re: /ignore\s+(?:all\s+)?(?:previous|prior|above)\s+instructions|disregard\s+(?:the\s+)?(?:system|previous|prior)|override\s+(?:your|the)\s+(?:instructions|system)|do\s+not\s+(?:tell|inform|mention\s+to)\s+the\s+user|without\s+(?:telling|informing|notifying)\s+the\s+user|do\s+not\s+mention\s+(?:this|these|that)|hide\s+(?:this|these)\s+from\s+the\s+user/i,
176
+ why: "Tells the model to keep secrets from you or to ignore its rules. A legitimate skill never needs this.",
177
+ fix: "Do not install it. Report it to the marketplace or the author.",
178
+ },
179
+ {
180
+ id: "exfiltration",
181
+ title: "Sends data to an outside endpoint",
182
+ severity: "critical",
183
+ capability: "exfiltration",
184
+ re: /discord(?:app)?\.com\/api\/webhooks|api\.telegram\.org\/bot|hooks\.slack\.com\/services|exfiltrat|(?:upload|send|post)[^\n]{0,50}(?:\.env|env\s+vars?|tokens?|secrets?|credentials?|ssh\s+keys?)[^\n]{0,50}(?:https?:\/\/|webhook|server)/i,
185
+ why: "Combines data with an outbound destination. This is the shape of a leak, even when it is labelled telemetry or analytics.",
186
+ fix: "Do not run it where real credentials exist. Check the destination and what is sent.",
187
+ },
188
+ {
189
+ id: "privilege-escalation",
190
+ title: "Asks for elevated privileges",
191
+ severity: "high",
192
+ capability: "exec",
193
+ re: /\bsudo\s+|\brunas\b|-Verb\s+RunAs\b|\bdoas\s+/i,
194
+ why: "Requests administrator rights. A skill that needs root to do its job deserves extra scrutiny.",
195
+ fix: "Run it as a normal user, or read exactly which privileged command it needs.",
196
+ },
197
+ ];
198
+
199
+ export const RULE_BY_ID = new Map(RULES.map((rule) => [rule.id, rule]));