@misconfig/cli 1.0.0 → 1.1.0
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/README.md +8 -4
- package/engine/catalog.js +4 -4
- package/engine/explain.js +438 -0
- package/engine/index.js +39 -20
- package/engine/mask.js +9 -2
- package/lib/main.js +5 -2
- package/lib/print.js +24 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Finds every file that controls your AI coding agents, on your computer and in your project, and checks them for risky settings.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npx @misconfig/cli@1.
|
|
6
|
+
npx @misconfig/cli@1.1.0
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
Run it in a project folder. It works on macOS, Windows and Linux with Node.js 18 or later, and needs no install or account.
|
|
10
10
|
|
|
11
|
-
On Windows, if PowerShell says running scripts is disabled, run `npx.cmd @misconfig/cli@1.
|
|
11
|
+
On Windows, if PowerShell says running scripts is disabled, run `npx.cmd @misconfig/cli@1.1.0` instead. There's no need to change your execution policy.
|
|
12
12
|
|
|
13
13
|
## What it checks
|
|
14
14
|
|
|
@@ -16,6 +16,8 @@ Claude Code, Claude Desktop, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode
|
|
|
16
16
|
|
|
17
17
|
Most of the files that control an agent sit outside your project, in hidden folders and app settings. misconfig reads them for you: `~/.claude/settings.json`, `~/.claude.json`, `~/.codex/config.toml`, Claude Desktop's MCP config, VS Code and Cursor settings, your shell profile and more. The full list, per operating system, is at https://misconfig.ai/#locations.
|
|
18
18
|
|
|
19
|
+
For each file it tells you, in plain words, what the file tells your agents: permission modes, commands allowed without asking, MCP servers and what they run, hooks, trusted folders, and what instruction files say, including text that's hidden when you read them. Add `--explain` to see all of it.
|
|
20
|
+
|
|
19
21
|
It looks for:
|
|
20
22
|
|
|
21
23
|
- **Permissions**: bypass modes, allow-everything shell rules, auto-approve settings and aliases that skip approvals.
|
|
@@ -28,7 +30,8 @@ It looks for:
|
|
|
28
30
|
- Everything runs on your computer. Without `--share`, misconfig makes no network requests.
|
|
29
31
|
- Credential files such as `.env` and `id_rsa` are listed by name only and never opened. Secrets inside agent files are masked as they're read.
|
|
30
32
|
- From `~/.claude.json` it reads only the MCP servers and the list of folders Claude Code has been started in.
|
|
31
|
-
-
|
|
33
|
+
- What it works out about your files, including everything `--explain` shows, stays on your computer.
|
|
34
|
+
- `--share` shows exactly what it will send and asks before sending. It sends this project's findings only: rule names, agent file names and line numbers. Names from your files, such as MCP servers, commands and packages, are left out, along with file contents, quoted lines, folder names and anything from the settings on your computer.
|
|
32
35
|
|
|
33
36
|
The checks are plain JavaScript in `engine/`, so you can read what runs before you run it.
|
|
34
37
|
|
|
@@ -37,6 +40,7 @@ The checks are plain JavaScript in `engine/`, so you can read what runs before y
|
|
|
37
40
|
```
|
|
38
41
|
npx @misconfig/cli [folder] [options]
|
|
39
42
|
|
|
43
|
+
--explain Show everything each file tells your agents
|
|
40
44
|
--share Publish this project's findings and print a link
|
|
41
45
|
--yes Share without asking, for scripts and CI
|
|
42
46
|
--json Print the full result as JSON
|
|
@@ -54,7 +58,7 @@ Exit codes: `0` when the check ran (and nothing reached `--fail-on`), `1` when `
|
|
|
54
58
|
Check the repository's agent files on every pull request:
|
|
55
59
|
|
|
56
60
|
```yaml
|
|
57
|
-
- run: npx @misconfig/cli@1.
|
|
61
|
+
- run: npx @misconfig/cli@1.1.0 --project-only --fail-on high
|
|
58
62
|
```
|
|
59
63
|
|
|
60
64
|
## Share links and badges
|
package/engine/catalog.js
CHANGED
|
@@ -179,7 +179,7 @@ export const RULES = {
|
|
|
179
179
|
severity: "medium", category: "mcp",
|
|
180
180
|
title: "MCP server “{server}” runs an unpinned package",
|
|
181
181
|
why: "“{command}” fetches the newest release every time it starts. A hijacked release would run with your agent's access.",
|
|
182
|
-
fix: "Pin an exact version,
|
|
182
|
+
fix: "Pin {pkg} to an exact version. To see the newest, run {lookup}.",
|
|
183
183
|
},
|
|
184
184
|
"MCP-HTTP": {
|
|
185
185
|
severity: "high", category: "mcp",
|
|
@@ -357,9 +357,9 @@ export const RULES = {
|
|
|
357
357
|
},
|
|
358
358
|
"WS-POISON-RISK": {
|
|
359
359
|
severity: "critical", category: "workspace",
|
|
360
|
-
title: "
|
|
361
|
-
why: "{files} in {
|
|
362
|
-
fix: "
|
|
360
|
+
title: "Files in {place} can give orders to agents started there",
|
|
361
|
+
why: "Instructions for an agent were found in {files}. An agent started in {place} treats the files there as context, and anything saved there later can add more.",
|
|
362
|
+
fix: "Start agents in project folders only, and delete instruction files you didn't write.",
|
|
363
363
|
},
|
|
364
364
|
"WS-OPENED-IN": {
|
|
365
365
|
severity: "high", category: "workspace",
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// What each file that controls an agent actually tells it to do, in plain
|
|
2
|
+
// words. This runs on the user's computer only. None of it is shared, sent
|
|
3
|
+
// or stored: share links and reports carry rule names, never these details.
|
|
4
|
+
|
|
5
|
+
import { describeMasks, maskSecrets } from "./mask.js";
|
|
6
|
+
|
|
7
|
+
const isObj = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
|
|
8
|
+
const strs = (x) => (Array.isArray(x) ? x.filter((s) => typeof s === "string" && s.trim()) : []);
|
|
9
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
10
|
+
const clean = (s) => describeMasks(String(s)).replace(/[\u{E0000}-\u{E007F}---]/gu, "");
|
|
11
|
+
const clip = (s, n = 90) => {
|
|
12
|
+
const t = clean(s).replace(/\s+/g, " ").trim();
|
|
13
|
+
return t.length > n ? `${t.slice(0, n - 1)}…` : t;
|
|
14
|
+
};
|
|
15
|
+
const list = (items, max = 4) => {
|
|
16
|
+
const shown = items.slice(0, max);
|
|
17
|
+
const rest = items.length - shown.length;
|
|
18
|
+
if (rest > 0) return `${shown.join(", ")} and ${rest} more`;
|
|
19
|
+
return shown.length < 2 ? shown.join("") : `${shown.slice(0, -1).join(", ")} and ${shown[shown.length - 1]}`;
|
|
20
|
+
};
|
|
21
|
+
const sentence = (s) => (s ? s.replace(/^./, (c) => c.toUpperCase()).replace(/([^.!?…”"])$/, "$1.") : s);
|
|
22
|
+
|
|
23
|
+
// Where a file's settings apply.
|
|
24
|
+
export function scopeOf(file) {
|
|
25
|
+
const p = file.path;
|
|
26
|
+
if (/(^|\/)managed-settings\.json$/i.test(p)) return "admin";
|
|
27
|
+
if (file.loose) return "loose";
|
|
28
|
+
if (/^(~|\/|[A-Za-z]:)/.test(p)) return "computer";
|
|
29
|
+
return "project";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const SCOPES = {
|
|
33
|
+
admin: "Set by an administrator, for everyone on this computer",
|
|
34
|
+
computer: "On this computer, for every project",
|
|
35
|
+
project: "In this project",
|
|
36
|
+
loose: "Loose files where agents have been started",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// { scope, summary, details } for one file. `json` is the parsed settings
|
|
40
|
+
// file (or null); `servers` are its MCP servers, already normalised.
|
|
41
|
+
export function explainFile(file, { json = null, servers = [] } = {}) {
|
|
42
|
+
const scope = scopeOf(file);
|
|
43
|
+
if (!file.content) return { scope, summary: file.tooLarge ? "Too large to read." : "Not read.", details: [] };
|
|
44
|
+
const p = file.path;
|
|
45
|
+
let out;
|
|
46
|
+
if (/(^|\/)(\.claude\/settings(\.local)?|managed-settings)\.json$/i.test(p)) out = claudeSettings(json);
|
|
47
|
+
else if (/(^|\/)\.claude\.json$/i.test(p)) out = claudeUserConfig(json);
|
|
48
|
+
else if (/(^|\/)\.codex\/config\.toml$/i.test(p)) out = codexConfig(json);
|
|
49
|
+
else if (/(^|\/)\.gemini\/settings\.json$/i.test(p)) out = geminiSettings(json);
|
|
50
|
+
else if (/(^|\/)(\.vscode|(Code|Code - Insiders|VSCodium|Cursor|Windsurf)\/User)\/settings\.json$/i.test(p)) out = editorSettings(json);
|
|
51
|
+
else if (/(^|\/)opencode\.jsonc?$/i.test(p)) out = openCode(json);
|
|
52
|
+
else if (/(^|\/)(\.zed|zed|Zed)\/settings\.json$/i.test(p)) out = zedSettings(json);
|
|
53
|
+
else if (/(^|\/)\.aider\.conf\.ya?ml$/i.test(p)) out = aiderConfig(file);
|
|
54
|
+
else if (file.kind === "Shell profile") out = shellProfile(file);
|
|
55
|
+
else if (file.kind === "Hook script") out = hookScript(file);
|
|
56
|
+
else if (/\.(jsonc?|toml)$/i.test(p)) out = { parts: [], details: [] };
|
|
57
|
+
else out = instructions(file);
|
|
58
|
+
|
|
59
|
+
// MCP servers, wherever they're defined.
|
|
60
|
+
if (servers.length) {
|
|
61
|
+
const on = servers.filter((s) => !s.disabled);
|
|
62
|
+
out.parts.push(on.length === servers.length ? `${plural(servers.length, "MCP server")}: ${list(servers.map((s) => s.name), 3)}` : `${plural(on.length, "MCP server")} on, ${servers.length - on.length} off`);
|
|
63
|
+
for (const s of servers) out.details.push(serverText(s));
|
|
64
|
+
}
|
|
65
|
+
const summary = out.summary ?? (out.parts.length ? out.parts.map(sentence).join(" ") : "Nothing that changes how an agent behaves.");
|
|
66
|
+
return { scope, summary, details: out.details };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function serverText(s) {
|
|
70
|
+
let what;
|
|
71
|
+
if (s.url) {
|
|
72
|
+
let host = "";
|
|
73
|
+
try {
|
|
74
|
+
host = new URL(s.url).host;
|
|
75
|
+
} catch {
|
|
76
|
+
host = clip(s.url, 40);
|
|
77
|
+
}
|
|
78
|
+
what = `connects to ${host}`;
|
|
79
|
+
} else what = `runs ${clip([s.command, ...s.args].filter(Boolean).join(" "), 80)}`;
|
|
80
|
+
const auto = s.alwaysAllow === true ? "; its tools run without asking" : strs(s.alwaysAllow).length ? `; runs ${list(strs(s.alwaysAllow), 3)} without asking` : "";
|
|
81
|
+
const env = Object.keys(s.env ?? {}).length ? `; sets ${list(Object.keys(s.env), 3)}` : "";
|
|
82
|
+
return `MCP server “${s.name}”${s.disabled ? " (turned off)" : ""}: ${what}${auto}${env}.`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --- Claude Code ------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
const CLAUDE_MODES = {
|
|
88
|
+
default: ["Asks before acting", "Asks before editing files or running commands."],
|
|
89
|
+
acceptEdits: ["Edits files without asking", "Edits files without asking, and asks before running commands."],
|
|
90
|
+
plan: ["Plan mode", "Starts in plan mode: it looks around but changes nothing until you approve a plan."],
|
|
91
|
+
bypassPermissions: ["Never asks", "Never asks: every permission prompt is turned off."],
|
|
92
|
+
dontAsk: ["Never asks", "Never asks for permission."],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const HOOK_EVENTS = {
|
|
96
|
+
PreToolUse: "Before each tool runs",
|
|
97
|
+
PostToolUse: "After each tool runs",
|
|
98
|
+
UserPromptSubmit: "When you send a prompt",
|
|
99
|
+
SessionStart: "When a session starts",
|
|
100
|
+
SessionEnd: "When a session ends",
|
|
101
|
+
Stop: "When Claude finishes a reply",
|
|
102
|
+
SubagentStop: "When a subagent finishes",
|
|
103
|
+
Notification: "When Claude sends a notification",
|
|
104
|
+
PreCompact: "Before the conversation is compacted",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
function claudeSettings(json) {
|
|
108
|
+
const parts = [];
|
|
109
|
+
const details = [];
|
|
110
|
+
if (!isObj(json)) return { parts, details, summary: "Couldn't read the settings in this file." };
|
|
111
|
+
const p = isObj(json.permissions) ? json.permissions : {};
|
|
112
|
+
const mode = CLAUDE_MODES[p.defaultMode];
|
|
113
|
+
if (mode) {
|
|
114
|
+
parts.push(mode[0]);
|
|
115
|
+
details.push(mode[1]);
|
|
116
|
+
} else if (typeof p.defaultMode === "string") details.push(`Permission mode: ${p.defaultMode}.`);
|
|
117
|
+
const allow = strs(p.allow);
|
|
118
|
+
const ask = strs(p.ask);
|
|
119
|
+
const deny = strs(p.deny);
|
|
120
|
+
if (allow.length) {
|
|
121
|
+
parts.push(`allows ${plural(allow.length, "action")} without asking`);
|
|
122
|
+
details.push(`Allowed without asking: ${list(allow.map((r) => clip(r, 60)), 8)}.`);
|
|
123
|
+
}
|
|
124
|
+
if (ask.length) details.push(`Always asks first: ${list(ask.map((r) => clip(r, 60)), 6)}.`);
|
|
125
|
+
if (deny.length) {
|
|
126
|
+
parts.push(`blocks ${plural(deny.length, "action")}`);
|
|
127
|
+
details.push(`Blocked: ${list(deny.map((r) => clip(r, 60)), 8)}.`);
|
|
128
|
+
}
|
|
129
|
+
const dirs = strs(p.additionalDirectories);
|
|
130
|
+
if (dirs.length) details.push(`Can also work in: ${list(dirs.map((d) => clip(d, 60)), 4)}.`);
|
|
131
|
+
|
|
132
|
+
let hookCount = 0;
|
|
133
|
+
if (isObj(json.hooks)) {
|
|
134
|
+
for (const [event, entries] of Object.entries(json.hooks)) {
|
|
135
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
136
|
+
const matcher = typeof entry?.matcher === "string" && entry.matcher && entry.matcher !== "*" ? ` (${clip(entry.matcher, 30)})` : "";
|
|
137
|
+
for (const h of Array.isArray(entry?.hooks) ? entry.hooks : [entry]) {
|
|
138
|
+
if (typeof h?.command !== "string") continue;
|
|
139
|
+
hookCount++;
|
|
140
|
+
details.push(`${HOOK_EVENTS[event] ?? event}${matcher}: runs ${clip(h.command, 80)}.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (hookCount) parts.push(hookCount === 1 ? "runs a command on a hook" : `runs ${hookCount} commands on hooks`);
|
|
146
|
+
if (isObj(json.env) && Object.keys(json.env).length) {
|
|
147
|
+
const keys = Object.keys(json.env);
|
|
148
|
+
parts.push(`sets ${plural(keys.length, "environment variable")}`);
|
|
149
|
+
details.push(`Sets ${list(keys, 6)} for the agent.`);
|
|
150
|
+
}
|
|
151
|
+
if (typeof json.model === "string") {
|
|
152
|
+
parts.push(`uses the ${json.model} model`);
|
|
153
|
+
details.push(`Uses the ${json.model} model.`);
|
|
154
|
+
}
|
|
155
|
+
if (json.enableAllProjectMcpServers === true) {
|
|
156
|
+
parts.push("turns on every project MCP server");
|
|
157
|
+
details.push("Turns on every MCP server a project's .mcp.json lists, without asking.");
|
|
158
|
+
}
|
|
159
|
+
const enabled = strs(json.enabledMcpjsonServers);
|
|
160
|
+
if (enabled.length) details.push(`Turns on these project MCP servers: ${list(enabled, 5)}.`);
|
|
161
|
+
if (typeof json.apiKeyHelper === "string") details.push(`Gets its API key by running ${clip(json.apiKeyHelper, 60)}.`);
|
|
162
|
+
if (isObj(json.statusLine) && typeof json.statusLine.command === "string") details.push(`Draws the status line by running ${clip(json.statusLine.command, 60)}.`);
|
|
163
|
+
if (typeof json.outputStyle === "string") details.push(`Uses the “${json.outputStyle}” output style.`);
|
|
164
|
+
return { parts, details };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ~/.claude.json, already reduced to MCP servers and the folders Claude Code
|
|
168
|
+
// has been started in. MCP servers are added by the caller.
|
|
169
|
+
function claudeUserConfig(json) {
|
|
170
|
+
const parts = [];
|
|
171
|
+
const details = [];
|
|
172
|
+
if (!isObj(json) || !isObj(json.projects)) return { parts, details };
|
|
173
|
+
const folders = Object.keys(json.projects);
|
|
174
|
+
const risky = folders.filter((d) => /^~$|\/(Downloads|Desktop)$/i.test(d) || /^([A-Za-z]:)?\/?$/.test(d));
|
|
175
|
+
const named = risky.map((d) => (d === "~" ? "your home folder" : /Downloads$/i.test(d) ? "Downloads" : /Desktop$/i.test(d) ? "Desktop" : d));
|
|
176
|
+
parts.push(`started in ${plural(folders.length, "folder")}${named.length ? `, including ${list(named, 3)}` : ""}`);
|
|
177
|
+
const shown = folders.map((d) => (d === "~" ? "~ (your home folder)" : d));
|
|
178
|
+
details.push(`Has been started in ${plural(folders.length, "folder")}: ${list(shown, 6)}.`);
|
|
179
|
+
const approvals = folders.filter((d) => strs(json.projects[d]?.allowedTools).length);
|
|
180
|
+
if (approvals.length) details.push(`Remembers commands you approved in ${plural(approvals.length, "folder")}: ${list(approvals, 4)}.`);
|
|
181
|
+
return { parts, details };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// --- Codex --------------------------------------------------------------------------
|
|
185
|
+
|
|
186
|
+
const CODEX_SANDBOX = {
|
|
187
|
+
"read-only": ["Read-only sandbox", "Sandbox: can read files but not change them."],
|
|
188
|
+
"workspace-write": ["Sandboxed to the project", "Sandbox: can change files only in the project folder."],
|
|
189
|
+
"danger-full-access": ["No sandbox", "No sandbox: commands can change any file and use the network."],
|
|
190
|
+
};
|
|
191
|
+
const CODEX_APPROVAL = {
|
|
192
|
+
untrusted: ["asks before most commands", "Asks before running anything outside a short list of safe commands."],
|
|
193
|
+
"on-failure": ["asks only when a command fails", "Runs commands in the sandbox and asks only when one fails."],
|
|
194
|
+
"on-request": ["asks when it decides to", "Asks only when it decides a command needs your approval."],
|
|
195
|
+
never: ["never asks", "Never asks for approval."],
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
function codexConfig(toml) {
|
|
199
|
+
const parts = [];
|
|
200
|
+
const details = [];
|
|
201
|
+
if (!isObj(toml)) return { parts, details, summary: "Couldn't read the settings in this file." };
|
|
202
|
+
const sandbox = CODEX_SANDBOX[toml.sandbox_mode];
|
|
203
|
+
if (sandbox) {
|
|
204
|
+
parts.push(sandbox[0]);
|
|
205
|
+
details.push(sandbox[1]);
|
|
206
|
+
}
|
|
207
|
+
const approval = CODEX_APPROVAL[toml.approval_policy];
|
|
208
|
+
if (approval) {
|
|
209
|
+
parts.push(approval[0]);
|
|
210
|
+
details.push(approval[1]);
|
|
211
|
+
}
|
|
212
|
+
if (toml.sandbox_workspace_write?.network_access === true) details.push("Lets sandboxed commands use the network.");
|
|
213
|
+
if (typeof toml.model === "string") details.push(`Uses the ${toml.model} model.`);
|
|
214
|
+
if (isObj(toml.projects)) {
|
|
215
|
+
const trusted = Object.entries(toml.projects).filter(([, s]) => s?.trust_level === "trusted").map(([d]) => d);
|
|
216
|
+
if (trusted.length) {
|
|
217
|
+
parts.push(`trusts ${plural(trusted.length, "folder")}`);
|
|
218
|
+
details.push(`Trusts ${list(trusted.map((d) => clip(d, 50)), 6)}.`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (isObj(toml.profiles) && Object.keys(toml.profiles).length) details.push(`Has ${plural(Object.keys(toml.profiles).length, "profile")}: ${list(Object.keys(toml.profiles), 4)}.`);
|
|
222
|
+
const notify = strs(toml.notify);
|
|
223
|
+
if (notify.length) details.push(`Runs ${clip(notify.join(" "), 60)} to send notifications.`);
|
|
224
|
+
return { parts, details };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// --- Gemini, editors, OpenCode, Zed, Aider ----------------------------------------------
|
|
228
|
+
|
|
229
|
+
function geminiSettings(json) {
|
|
230
|
+
const parts = [];
|
|
231
|
+
const details = [];
|
|
232
|
+
if (!isObj(json)) return { parts, details };
|
|
233
|
+
const mode = json.approvalMode ?? json.general?.approvalMode ?? json.tools?.approvalMode;
|
|
234
|
+
if (json.yolo === true || /^yolo$/i.test(String(mode))) {
|
|
235
|
+
parts.push("Never asks (YOLO mode)");
|
|
236
|
+
details.push("YOLO mode: runs every tool call without asking.");
|
|
237
|
+
} else if (json.autoAccept === true || json.tools?.autoAccept === true || /^auto_edit$/i.test(String(mode))) {
|
|
238
|
+
parts.push("Accepts some tool calls without asking");
|
|
239
|
+
details.push("Accepts tool calls it considers safe without asking.");
|
|
240
|
+
}
|
|
241
|
+
const sandbox = json.sandbox ?? json.tools?.sandbox;
|
|
242
|
+
if (sandbox !== undefined) details.push(sandbox ? `Runs tools in a sandbox${typeof sandbox === "string" ? ` (${sandbox})` : ""}.` : "Sandbox turned off.");
|
|
243
|
+
const allowed = strs(json.coreTools ?? json.tools?.core ?? json.tools?.allowed);
|
|
244
|
+
if (allowed.length) details.push(`Tools it may use: ${list(allowed, 6)}.`);
|
|
245
|
+
const excluded = strs(json.excludeTools ?? json.tools?.exclude);
|
|
246
|
+
if (excluded.length) details.push(`Tools it may not use: ${list(excluded, 6)}.`);
|
|
247
|
+
return { parts, details };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function editorSettings(json) {
|
|
251
|
+
const parts = [];
|
|
252
|
+
const details = [];
|
|
253
|
+
if (!isObj(json)) return { parts, details };
|
|
254
|
+
if (json["chat.tools.autoApprove"] === true || json["chat.tools.global.autoApprove"] === true) {
|
|
255
|
+
parts.push("Runs agent tools without asking");
|
|
256
|
+
details.push("Agent mode runs tools and terminal commands without asking.");
|
|
257
|
+
}
|
|
258
|
+
const terminal = json["chat.tools.terminal.autoApprove"] ?? json["github.copilot.chat.agent.terminal.allowList"];
|
|
259
|
+
if (isObj(terminal)) {
|
|
260
|
+
const on = Object.entries(terminal).filter(([, v]) => v === true || (isObj(v) && v.approve === true)).map(([k]) => k);
|
|
261
|
+
const off = Object.entries(terminal).filter(([, v]) => v === false || (isObj(v) && v.approve === false)).map(([k]) => k);
|
|
262
|
+
if (on.length) {
|
|
263
|
+
parts.push(`${plural(on.length, "terminal command")} approved automatically`);
|
|
264
|
+
details.push(`Terminal commands that run without asking: ${list(on.map((k) => clip(k, 40)), 6)}.`);
|
|
265
|
+
}
|
|
266
|
+
if (off.length) details.push(`Terminal commands that always ask: ${list(off.map((k) => clip(k, 40)), 6)}.`);
|
|
267
|
+
}
|
|
268
|
+
const agentKeys = Object.keys(json).filter((k) => /^(chat\.|github\.copilot|cursor\.|windsurf\.|codeium\.)/i.test(k));
|
|
269
|
+
if (agentKeys.length && !parts.length) details.push(`Changes ${plural(agentKeys.length, "agent setting")}: ${list(agentKeys, 5)}.`);
|
|
270
|
+
if (!agentKeys.length && !isObj(json.mcp)) return { parts, details, summary: "No agent settings changed." };
|
|
271
|
+
return { parts, details };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function openCode(json) {
|
|
275
|
+
const parts = [];
|
|
276
|
+
const details = [];
|
|
277
|
+
if (!isObj(json)) return { parts, details };
|
|
278
|
+
const perm = isObj(json.permission) ? json.permission : {};
|
|
279
|
+
for (const tool of ["edit", "bash", "webfetch"]) {
|
|
280
|
+
const v = perm[tool];
|
|
281
|
+
if (typeof v === "string") details.push(`${tool === "webfetch" ? "Web requests" : tool === "bash" ? "Shell commands" : "File edits"}: ${v === "allow" ? "run without asking" : v === "ask" ? "asks first" : v === "deny" ? "blocked" : v}.`);
|
|
282
|
+
}
|
|
283
|
+
if (perm.bash === "allow" || (isObj(perm.bash) && perm.bash["*"] === "allow")) parts.push("Runs shell commands without asking");
|
|
284
|
+
if (json.share === "auto") {
|
|
285
|
+
parts.push("shares every session automatically");
|
|
286
|
+
details.push("Shares every session to a public link automatically.");
|
|
287
|
+
} else if (typeof json.share === "string") details.push(`Session sharing: ${json.share}.`);
|
|
288
|
+
if (typeof json.model === "string") details.push(`Uses the ${json.model} model.`);
|
|
289
|
+
if (isObj(json.agent) && Object.keys(json.agent).length) details.push(`Defines ${plural(Object.keys(json.agent).length, "agent")}: ${list(Object.keys(json.agent), 4)}.`);
|
|
290
|
+
return { parts, details };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function zedSettings(json) {
|
|
294
|
+
const parts = [];
|
|
295
|
+
const details = [];
|
|
296
|
+
if (!isObj(json)) return { parts, details };
|
|
297
|
+
if (json.agent?.always_allow_tool_actions === true || json.assistant?.always_allow_tool_actions === true) {
|
|
298
|
+
parts.push("Runs agent tools without asking");
|
|
299
|
+
details.push("The agent runs tool actions without asking.");
|
|
300
|
+
}
|
|
301
|
+
const model = json.agent?.default_model?.model ?? json.assistant?.default_model?.model;
|
|
302
|
+
if (typeof model === "string") details.push(`Uses the ${model} model.`);
|
|
303
|
+
if (!parts.length && !details.length && !isObj(json.context_servers)) return { parts, details, summary: "No agent settings changed." };
|
|
304
|
+
return { parts, details };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function aiderConfig(file) {
|
|
308
|
+
const parts = [];
|
|
309
|
+
const details = [];
|
|
310
|
+
for (const line of file.lines ?? []) {
|
|
311
|
+
const m = line.match(/^\s*([a-z0-9-]+)\s*:\s*(.+?)\s*$/i);
|
|
312
|
+
if (!m) continue;
|
|
313
|
+
const [, key, value] = m;
|
|
314
|
+
if (key === "yes-always" && /^true$/i.test(value)) {
|
|
315
|
+
parts.push("Confirms everything without asking");
|
|
316
|
+
details.push("Answers yes to every confirmation, including running commands.");
|
|
317
|
+
} else if (key === "model") details.push(`Uses the ${clip(value, 40)} model.`);
|
|
318
|
+
else if (key === "auto-commits") details.push(`Commits changes automatically: ${value}.`);
|
|
319
|
+
}
|
|
320
|
+
return { parts, details };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// --- Shell profiles and hook scripts -----------------------------------------------------
|
|
324
|
+
|
|
325
|
+
const AGENT_COMMANDS = /\b(claude|codex|gemini|qwen|opencode|cursor-agent|aider|amp|copilot|grok|kiro|q chat)\b/i;
|
|
326
|
+
const AGENT_ENV = /\b(ANTHROPIC|CLAUDE|OPENAI|CODEX|GEMINI|GOOGLE_GENAI|XAI|GROK|OPENROUTER|MISTRAL|DEEPSEEK)_[A-Z0-9_]+/;
|
|
327
|
+
|
|
328
|
+
// Lines in a shell profile that change how an agent starts or runs.
|
|
329
|
+
export function agentLines(file) {
|
|
330
|
+
const out = [];
|
|
331
|
+
for (const [i, line] of (file.lines ?? []).entries()) {
|
|
332
|
+
if (/^\s*#/.test(line) || !line.trim()) continue;
|
|
333
|
+
if (AGENT_COMMANDS.test(line) || AGENT_ENV.test(line)) out.push({ line: i + 1, text: line });
|
|
334
|
+
}
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function shellProfile(file) {
|
|
339
|
+
const parts = [];
|
|
340
|
+
const details = [];
|
|
341
|
+
const lines = agentLines(file);
|
|
342
|
+
for (const { line, text } of lines) {
|
|
343
|
+
const flag = text.match(/--?(dangerously-[a-z-]+|yolo|full-auto|yes-always|always-approve|allow-all-tools|dangerously-bypass-approvals-and-sandbox)\b/i);
|
|
344
|
+
const agent = text.match(AGENT_COMMANDS)?.[1];
|
|
345
|
+
const env = text.match(AGENT_ENV)?.[0];
|
|
346
|
+
if (flag && agent) {
|
|
347
|
+
parts.push(`starts ${agent} with ${flag[0]}`);
|
|
348
|
+
details.push(`Line ${line}: every time you run ${agent}, it adds ${flag[0]}.`);
|
|
349
|
+
} else if (env) details.push(`Line ${line}: sets ${env} for every program you run.`);
|
|
350
|
+
else details.push(`Line ${line}: ${clip(text, 80)}`);
|
|
351
|
+
}
|
|
352
|
+
if (!lines.length) return { parts, details, summary: "Nothing agent-related." };
|
|
353
|
+
if (!parts.length) parts.push(`${plural(lines.length, "line")} about agents`);
|
|
354
|
+
return { parts, details };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function hookScript(file) {
|
|
358
|
+
const commands = (file.lines ?? []).filter((l) => l.trim() && !/^\s*(#|\/\/|rem\b)/i.test(l));
|
|
359
|
+
return {
|
|
360
|
+
parts: [`hook script, ${plural(commands.length, "command line")}`],
|
|
361
|
+
details: commands.slice(0, 6).map((l) => `Runs: ${clip(l, 80)}`),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// --- Instruction files ------------------------------------------------------------------
|
|
366
|
+
|
|
367
|
+
const DIRECTIVE =
|
|
368
|
+
/^(?:always|never|don['’]?t|do not|must|should|use|run|prefer|avoid|make sure|ensure|keep|write|follow|add|remove|only|ignore|install|call|send|read|check|before|after|when|if|you|please|import|create|update|delete|commit|push|test|format|name|put|store|respond|reply|answer|ask|tell|do)\b/i;
|
|
369
|
+
|
|
370
|
+
function frontmatter(text) {
|
|
371
|
+
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
372
|
+
if (!m) return {};
|
|
373
|
+
const out = {};
|
|
374
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
375
|
+
const kv = line.match(/^([A-Za-z][\w-]*)\s*:\s*(.*)$/);
|
|
376
|
+
if (kv) out[kv[1].toLowerCase()] = kv[2].trim().replace(/^["']|["']$/g, "");
|
|
377
|
+
}
|
|
378
|
+
return out;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function instructions(file) {
|
|
382
|
+
const text = file.content.slice(0, 200_000);
|
|
383
|
+
const fm = frontmatter(text);
|
|
384
|
+
const body = text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "");
|
|
385
|
+
const lines = body.split(/\r?\n/);
|
|
386
|
+
const nonEmpty = lines.filter((l) => l.trim()).length;
|
|
387
|
+
const headings = lines.filter((l) => /^#{1,3}\s+\S/.test(l)).map((l) => clip(l.replace(/^#+\s*/, ""), 40));
|
|
388
|
+
const imports = [...body.matchAll(/(?:^|\s)@([~.\w/-][^\s]*\.\w+)/g)].map((m) => `@${m[1]}`);
|
|
389
|
+
// What it says, in the order it says it.
|
|
390
|
+
const said = [];
|
|
391
|
+
let fence = false;
|
|
392
|
+
for (const raw of lines) {
|
|
393
|
+
if (/^\s*(```|~~~)/.test(raw)) fence = !fence;
|
|
394
|
+
if (fence || /^\s*(#|```|~~~|<!--|-->|\|?\s*-{3,})/.test(raw)) continue;
|
|
395
|
+
const l = clean(raw).replace(/<!--[\s\S]*?-->/g, "").replace(/^\s*(?:[-*+]|\d+[.)])\s+/, "").replace(/\*\*/g, "").trim();
|
|
396
|
+
if (l.length >= 4 && !/^@\S+$/.test(l)) said.push(l);
|
|
397
|
+
if (said.length >= 40) break;
|
|
398
|
+
}
|
|
399
|
+
const directives = said.filter((l) => DIRECTIVE.test(l));
|
|
400
|
+
const example = directives[0] ?? said[0];
|
|
401
|
+
|
|
402
|
+
// What it says that people can't see: invisible characters and comments.
|
|
403
|
+
const hidden = [];
|
|
404
|
+
for (const m of text.matchAll(/[\u{E0000}-\u{E007F}]+/gu)) {
|
|
405
|
+
const decoded = [...m[0]].map((ch) => String.fromCharCode(ch.codePointAt(0) - 0xe0000)).join("").replace(/[^\x20-\x7e]/g, "").trim();
|
|
406
|
+
if (decoded) hidden.push(`Hidden text you can't see when it's displayed: “${clip(maskSecrets(decoded).text, 100)}”`);
|
|
407
|
+
}
|
|
408
|
+
for (const m of text.matchAll(/<!--([\s\S]*?)-->/g)) {
|
|
409
|
+
const inner = m[1].trim();
|
|
410
|
+
if (inner.length >= 8 && !/^(prettier-|eslint-|markdownlint|toc|end|start|region|endregion)/i.test(inner)) hidden.push(`Hidden in a comment: “${clip(inner, 100)}”`);
|
|
411
|
+
if (hidden.length >= 4) break;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const p = file.path;
|
|
415
|
+
const name = fm.name ?? p.split("/").slice(-2, -1)[0];
|
|
416
|
+
const parts = [];
|
|
417
|
+
const details = [];
|
|
418
|
+
if (/(^|\/)\.claude\/skills\/[^/]+\/SKILL\.md$/i.test(p) || /(^|\/)\.claude\/(agents|commands)\//i.test(p)) {
|
|
419
|
+
const kind = /\/skills\//i.test(p) ? "Skill" : /\/agents\//i.test(p) ? "Subagent" : "Command";
|
|
420
|
+
const label = kind === "Command" ? `/${p.split("/").pop().replace(/\.md$/i, "")}` : `“${name}”`;
|
|
421
|
+
parts.push(`${kind} ${label}${fm.description ? `: ${clip(fm.description, 70)}` : ""}`);
|
|
422
|
+
const tools = fm["allowed-tools"] ?? fm.tools;
|
|
423
|
+
if (tools) details.push(`Can use: ${clip(tools, 80)}.`);
|
|
424
|
+
if (fm.model) details.push(`Uses the ${fm.model} model.`);
|
|
425
|
+
} else {
|
|
426
|
+
parts.push(`${plural(nonEmpty, "line")} of instructions${example ? `, such as “${clip(example, 60)}”` : ""}`);
|
|
427
|
+
}
|
|
428
|
+
if (hidden.length) parts.push("also contains text that's hidden when you read it");
|
|
429
|
+
if (fm.alwaysapply === "true") details.push("Applies to every request.");
|
|
430
|
+
else if (fm.globs || fm.applyto) details.push(`Applies to files matching ${clip(fm.globs || fm.applyto, 60)}.`);
|
|
431
|
+
else if (fm.description && !/skills|agents|commands/i.test(p)) details.push(`Applies when relevant to: ${clip(fm.description, 70)}.`);
|
|
432
|
+
if (headings.length) details.push(`Sections: ${list(headings, 6)}.`);
|
|
433
|
+
if (imports.length) details.push(`Pulls in ${list([...new Set(imports)].map((i) => clip(i, 50)), 4)}.`);
|
|
434
|
+
details.push(...hidden);
|
|
435
|
+
for (const d of said.slice(0, 8)) details.push(`Says: “${clip(d, 90)}”`);
|
|
436
|
+
if (said.length > 8) details.push(`And ${plural(said.length - 8, "more line")}${said.length >= 40 ? " or more" : ""}.`);
|
|
437
|
+
return { parts, details };
|
|
438
|
+
}
|
package/engine/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// misconfig.ai rule engine. Runs only in the Worker, never in the browser.
|
|
2
2
|
|
|
3
|
-
import { maskSecrets, looksLikeSecret, looksLikeToken, isMasked, describeMasks } from "./mask.js";
|
|
3
|
+
import { maskSecrets, looksLikeSecret, looksLikeToken, isMasked, isPathLike, describeMasks } from "./mask.js";
|
|
4
4
|
import { parseJSONC, parseTOML } from "./parse.js";
|
|
5
5
|
import { RULES, CATEGORIES } from "./catalog.js";
|
|
6
|
+
import { explainFile, agentLines } from "./explain.js";
|
|
6
7
|
|
|
7
|
-
export const RULESET_VERSION = "2026.11.
|
|
8
|
+
export const RULESET_VERSION = "2026.11.2";
|
|
8
9
|
|
|
9
10
|
const WEIGHT = { critical: 30, high: 15, medium: 6, low: 2, info: 0 };
|
|
10
11
|
const SEVERITIES = ["critical", "high", "medium", "low", "info"];
|
|
@@ -13,6 +14,8 @@ const MAX_FILE_CHARS = 450_000;
|
|
|
13
14
|
// Which agents read which files. Used for the control map and attribution.
|
|
14
15
|
const CONTROL = [
|
|
15
16
|
[/(^|\/)claude(\.local)?\.md$/i, ["Claude Code"], "Instructions"],
|
|
17
|
+
[/(^|\/)\.codex\/agents(\.override)?\.md$/i, ["Codex"], "Instructions"],
|
|
18
|
+
[/(^|\/)\.config\/opencode\/agents\.md$/i, ["OpenCode"], "Instructions"],
|
|
16
19
|
[/(^|\/)agents(\.override)?\.md$/i, ["Codex", "OpenCode", "Cursor", "GitHub Copilot", "Zed"], "Instructions"],
|
|
17
20
|
[/(^|\/)gemini\.md$/i, ["Gemini CLI"], "Instructions"],
|
|
18
21
|
[/(^|\/)\.claude\/settings(\.local)?\.json$/i, ["Claude Code"], "Permissions & hooks"],
|
|
@@ -262,14 +265,19 @@ function fillTemplate(text, values) {
|
|
|
262
265
|
return text.replace(/\{(\w+)\}/g, (_, k) => values[k] ?? "");
|
|
263
266
|
}
|
|
264
267
|
|
|
265
|
-
// Parts of a finding that
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
+
// Parts of a finding that come from the user's own files: quoted text, paths,
|
|
269
|
+
// commands and the names people choose for servers, packages, variables and
|
|
270
|
+
// files. They never leave the computer. Shared reports show "[hidden]".
|
|
271
|
+
const PRIVATE_VARS = new Set(["cmd", "decoded", "phrase", "host", "ref", "path", "dir", "command", "rule", "files", "list", "key", "server", "pkg", "lookup", "root"]);
|
|
272
|
+
|
|
273
|
+
// "where" is a fixed phrase that can quote a name, as in The “deploy” script.
|
|
274
|
+
const hideNames = (text) => String(text).replace(/“[^”]*”/g, "“[hidden]”");
|
|
268
275
|
|
|
269
276
|
export function publicFinding(f) {
|
|
270
277
|
const rule = RULES[f.id];
|
|
271
278
|
const values = { ...(f.vars ?? {}) };
|
|
272
|
-
for (const k of PRIVATE_VARS) values[k] = "[
|
|
279
|
+
for (const k of PRIVATE_VARS) values[k] = "[hidden]";
|
|
280
|
+
if (typeof values.where === "string") values.where = hideNames(values.where);
|
|
273
281
|
const fill = (text, fallback) => (rule ? fillTemplate(text, values) : fallback);
|
|
274
282
|
return {
|
|
275
283
|
id: f.id,
|
|
@@ -603,7 +611,7 @@ function checkInstructionText(ctx, f) {
|
|
|
603
611
|
textRule("TXT-IMPORT-OUTSIDE", RX_IMPORT_OUTSIDE, (m) => ({ ref: "@" + clip(m[1], 80) }));
|
|
604
612
|
textRule("FLAG-DOCS", RX_DANGER_FLAGS, (m) => ({ flag: m[0].trim() }), { affirmative: true });
|
|
605
613
|
|
|
606
|
-
if (text.length > 60_000) add(ctx, "TXT-HUGE", { file: f, vars: { size: `${Math.round(text.length / 1024)} KB` } });
|
|
614
|
+
if (text.length > 60_000 && !f.loose) add(ctx, "TXT-HUGE", { file: f, vars: { size: `${Math.round(text.length / 1024)} KB` } });
|
|
607
615
|
}
|
|
608
616
|
|
|
609
617
|
// --- MCP servers -------------------------------------------------------------------
|
|
@@ -663,7 +671,7 @@ function normalizeServer(name, def, file) {
|
|
|
663
671
|
const REFERENCE = /^\$\{[^}]+\}$|^\$[A-Za-z_][A-Za-z0-9_]*$|^\{env:[^}]+\}$|^%[A-Za-z_][A-Za-z0-9_]*%$|\$\{(?:env|input):/i;
|
|
664
672
|
|
|
665
673
|
function isSecretValue(key, value) {
|
|
666
|
-
if (typeof value !== "string" || REFERENCE.test(value.trim())) return false;
|
|
674
|
+
if (typeof value !== "string" || REFERENCE.test(value.trim()) || isPathLike(value)) return false;
|
|
667
675
|
if (isMasked(value)) return true;
|
|
668
676
|
if (/^(true|false|\d+|https?:\/\/[^@]*)$/i.test(value)) return false;
|
|
669
677
|
return /(token|secret|key|password|passwd|auth|credential|bearer|cookie|session)/i.test(key) ? looksLikeSecret(value) || value.length >= 20 : looksLikeToken(value) && value.length >= 24;
|
|
@@ -712,7 +720,7 @@ function checkMcpServer(ctx, s) {
|
|
|
712
720
|
if (pkg && !pkg.pinned) {
|
|
713
721
|
add(ctx, "MCP-UNPINNED", {
|
|
714
722
|
...base(lineOf(f, pkg.spec) || nameLine),
|
|
715
|
-
vars: { server: s.name, command: clip([s.command, ...s.args].join(" "), 90), pkg: pkg.name },
|
|
723
|
+
vars: { server: s.name, command: clip([s.command, ...s.args].join(" "), 90), pkg: pkg.name, lookup: pkg.python ? `pip index versions ${pkg.name}` : `npm view ${pkg.name} version` },
|
|
716
724
|
});
|
|
717
725
|
}
|
|
718
726
|
|
|
@@ -763,7 +771,7 @@ function judgeSpec(spec, python) {
|
|
|
763
771
|
if (!spec) return null;
|
|
764
772
|
if (python) {
|
|
765
773
|
const name = spec.split(/[=@<>~!\[]/)[0];
|
|
766
|
-
return { name, spec, pinned: /==\s*\d|@\s*\d/.test(spec) };
|
|
774
|
+
return { name, spec, pinned: /==\s*\d|@\s*\d/.test(spec), python: true };
|
|
767
775
|
}
|
|
768
776
|
if (/^(\.|\/|[a-z]+:|~)/i.test(spec)) return null; // local path or URL
|
|
769
777
|
const at = spec.lastIndexOf("@");
|
|
@@ -818,8 +826,8 @@ function checkWorkspace(ctx) {
|
|
|
818
826
|
if (downloadsLike) add(ctx, "WS-DOWNLOADS", { vars: { root } });
|
|
819
827
|
|
|
820
828
|
if (downloadsLike) {
|
|
821
|
-
const steering = ctx.files.filter((f) => f.content && (f.kind || f.loose) && isInstructionFile(f) && (!f.loose ||
|
|
822
|
-
if (steering.length) add(ctx, "WS-POISON-RISK", { vars: { files: listNames(steering.map((f) => f.path), 3), root } });
|
|
829
|
+
const steering = ctx.files.filter((f) => f.content && (f.kind || f.loose) && isInstructionFile(f) && (!f.loose || steers(ctx, f)));
|
|
830
|
+
if (steering.length) add(ctx, "WS-POISON-RISK", { vars: { files: listNames(steering.map((f) => f.path), 3), place: `your ${root} folder` } });
|
|
823
831
|
}
|
|
824
832
|
|
|
825
833
|
const looseByDir = new Map();
|
|
@@ -831,8 +839,8 @@ function checkWorkspace(ctx) {
|
|
|
831
839
|
}
|
|
832
840
|
for (const [dir, list] of looseByDir) {
|
|
833
841
|
if (!riskyPlace(dir)) continue;
|
|
834
|
-
const steering = list.filter((f) =>
|
|
835
|
-
if (steering.length) add(ctx, "WS-POISON-RISK", { vars: { files: listNames(steering.map((f) => f.path.split("/").pop()), 3),
|
|
842
|
+
const steering = list.filter((f) => steers(ctx, f));
|
|
843
|
+
if (steering.length) add(ctx, "WS-POISON-RISK", { vars: { files: listNames(steering.map((f) => f.path.split("/").pop()), 3), place: riskyPlace(dir).name } });
|
|
836
844
|
}
|
|
837
845
|
|
|
838
846
|
if (ctx.shape.gitRepos >= 3) add(ctx, "WS-MULTI-REPO", { vars: { count: ctx.shape.gitRepos } });
|
|
@@ -881,8 +889,12 @@ function denyCovers(rule, path) {
|
|
|
881
889
|
}
|
|
882
890
|
}
|
|
883
891
|
|
|
884
|
-
|
|
885
|
-
|
|
892
|
+
// A loose file counts as steering an agent only when it reads like orders to
|
|
893
|
+
// one, or carries an injection pattern. Size and encoded blobs don't count:
|
|
894
|
+
// page dumps and logs are full of both.
|
|
895
|
+
const STEERING_RULES = new Set(["TXT-TAGS", "TXT-BIDI", "TXT-ZERO-WIDTH", "TXT-HIDDEN-COMMENT", "TXT-REMOTE-EXEC", "TXT-EXFIL", "TXT-OVERRIDE", "TXT-SECRET-ACCESS", "FLAG-DOCS"]);
|
|
896
|
+
function steers(ctx, f) {
|
|
897
|
+
return Boolean(f.content) && (RX_DIRECTIVE.test(f.content) || ctx.findings.some((x) => x.file === f.path && STEERING_RULES.has(x.id)));
|
|
886
898
|
}
|
|
887
899
|
|
|
888
900
|
function listNames(names, max = 4) {
|
|
@@ -905,7 +917,7 @@ function walk(obj, visit, depth = 0) {
|
|
|
905
917
|
// --- Sprawl ------------------------------------------------------------------------
|
|
906
918
|
|
|
907
919
|
function checkSprawl(ctx) {
|
|
908
|
-
const steering = ctx.files.filter((f) => f.content && f.kind && isInstructionFile(f) && !/(^|\/)\.(claude|github|codex|opencode)\/(commands|prompts|agents|chatmodes|skills|output-styles)\//i.test(f.path));
|
|
920
|
+
const steering = ctx.files.filter((f) => f.content && f.kind && !f.loose && isInstructionFile(f) && !/(^|\/)\.(claude|github|codex|opencode)\/(commands|prompts|agents|chatmodes|skills|output-styles)\//i.test(f.path));
|
|
909
921
|
const tools = new Set(steering.flatMap((f) => f.tools));
|
|
910
922
|
if (steering.length >= 4 && tools.size >= 3) {
|
|
911
923
|
add(ctx, "SPRAWL", { vars: { count: steering.length, list: listNames(steering.map((f) => f.path), 4) } });
|
|
@@ -941,7 +953,7 @@ function agentsIn(controlMap) {
|
|
|
941
953
|
|
|
942
954
|
function summarize(ctx) {
|
|
943
955
|
const findings = ctx.findings.sort(bySeverity);
|
|
944
|
-
const controlFiles = ctx.files.filter((f) => f.kind);
|
|
956
|
+
const controlFiles = ctx.files.filter((f) => f.kind && (!f.loose || steers(ctx, f)) && (f.kind !== "Shell profile" || !f.content || agentLines(f).length));
|
|
945
957
|
const { counts, score, grade } = scoreFindings(findings, controlFiles.length > 0);
|
|
946
958
|
const toolNames = agentsIn(controlFiles);
|
|
947
959
|
const headline = headlineFor(counts, findings[0], controlFiles.length > 0);
|
|
@@ -957,6 +969,8 @@ function summarize(ctx) {
|
|
|
957
969
|
findings,
|
|
958
970
|
categories: CATEGORIES,
|
|
959
971
|
tools: toolNames,
|
|
972
|
+
// What each file tells its agents, worked out here and shown only here:
|
|
973
|
+
// the share payload keeps just the path.
|
|
960
974
|
controlMap: controlFiles.map((f) => ({
|
|
961
975
|
path: f.path,
|
|
962
976
|
kind: f.kind,
|
|
@@ -964,6 +978,7 @@ function summarize(ctx) {
|
|
|
964
978
|
size: f.size,
|
|
965
979
|
lines: f.lines ? f.lines.length : null,
|
|
966
980
|
findings: findings.filter((x) => x.file === f.path).length,
|
|
981
|
+
...explainFile(f, { json: f.content && /\.(jsonc?|toml)$/i.test(f.path) ? parsed(f) : null, servers: ctx.mcpServers.filter((s) => s.file === f) }),
|
|
967
982
|
})),
|
|
968
983
|
stats: {
|
|
969
984
|
filesChecked: ctx.files.filter((f) => f.content).length,
|
|
@@ -989,7 +1004,11 @@ export function toShareable(result) {
|
|
|
989
1004
|
file: f.file,
|
|
990
1005
|
line: f.line,
|
|
991
1006
|
// The file name travels once, as file; the report rebuilds the rest.
|
|
992
|
-
vars: Object.fromEntries(
|
|
1007
|
+
vars: Object.fromEntries(
|
|
1008
|
+
Object.entries(f.vars ?? {})
|
|
1009
|
+
.filter(([k]) => k !== "file" && !PRIVATE_VARS.has(k))
|
|
1010
|
+
.map(([k, v]) => [k, k === "where" ? hideNames(v) : v]),
|
|
1011
|
+
),
|
|
993
1012
|
})),
|
|
994
1013
|
controlMap: result.controlMap.map((f) => f.path),
|
|
995
1014
|
stats: { filesChecked: result.stats.filesChecked, mcpServers: result.stats.mcpServers },
|
|
@@ -1015,7 +1034,7 @@ export function publicReportFrom(payload) {
|
|
|
1015
1034
|
const rule = RULES[f.id];
|
|
1016
1035
|
const allowed = new Set([...`${rule.title} ${rule.why} ${rule.fix}`.matchAll(/\{(\w+)\}/g)].map((m) => m[1]));
|
|
1017
1036
|
const vars = {};
|
|
1018
|
-
for (const [k, v] of Object.entries(isObj(f.vars) ? f.vars : {})) if (allowed.has(k) && !PRIVATE_VARS.has(k)) vars[k] = safe(v);
|
|
1037
|
+
for (const [k, v] of Object.entries(isObj(f.vars) ? f.vars : {})) if (allowed.has(k) && !PRIVATE_VARS.has(k)) vars[k] = safe(k === "where" ? hideNames(v) : v);
|
|
1019
1038
|
const file = typeof f.file === "string" ? projectPath(f.file) : null;
|
|
1020
1039
|
vars.file = file ?? "";
|
|
1021
1040
|
const control = file ? controlFor(file) : null;
|
package/engine/mask.js
CHANGED
|
@@ -66,6 +66,13 @@ export function looksLikeSecret(value) {
|
|
|
66
66
|
return v.length >= 16 && classes >= 2 && entropy(v) >= 3.3 && !/\s/.test(v);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// File paths and path lists, such as C:\Users\sam\AppData\..., /usr/lib/node,
|
|
70
|
+
// ~/.config/app or %APPDATA%\app. A path can point at a secret, but it isn't one.
|
|
71
|
+
export function isPathLike(value) {
|
|
72
|
+
const first = String(value).trim().split(";")[0];
|
|
73
|
+
return /^(?:[A-Za-z]:[\\/]|\\\\|\/(?!\/)[^/\s]*\/|~[\\/]|\.{1,2}[\\/]|%[A-Za-z_][A-Za-z0-9_]*%[\\/]?|\$(?:HOME|\{HOME\})[\\/])/.test(first);
|
|
74
|
+
}
|
|
75
|
+
|
|
69
76
|
// Stricter, for strings with no key name to go on, such as command arguments.
|
|
70
77
|
// Random tokens mix letters and digits; names like GITHUB_TOKEN, flags like
|
|
71
78
|
// --dangerously-skip-permissions and package names are made of words and
|
|
@@ -79,7 +86,7 @@ export function looksLikeToken(value) {
|
|
|
79
86
|
re.lastIndex = 0;
|
|
80
87
|
if (re.test(v)) return true;
|
|
81
88
|
}
|
|
82
|
-
if (!/[0-9]/.test(v) || !/[A-Za-z]/.test(v)) return false;
|
|
89
|
+
if (!/[0-9]/.test(v) || !/[A-Za-z]/.test(v) || isPathLike(v)) return false;
|
|
83
90
|
if (v.split(/[-_.:@+]/).every((part) => !part || WORDY.test(part))) return false;
|
|
84
91
|
return looksLikeSecret(v);
|
|
85
92
|
}
|
|
@@ -102,7 +109,7 @@ export function maskSecrets(text) {
|
|
|
102
109
|
}
|
|
103
110
|
const keepPrefix = (kind) => (match, prefix, value) => {
|
|
104
111
|
if (isMasked(value) || PLACEHOLDER.test(value)) return match;
|
|
105
|
-
if (kind === "assigned-secret" && !looksLikeSecret(value)) return match;
|
|
112
|
+
if (kind === "assigned-secret" && (!looksLikeSecret(value) || isPathLike(value))) return match;
|
|
106
113
|
note(kind);
|
|
107
114
|
return prefix + marker(kind, value.length);
|
|
108
115
|
};
|
package/lib/main.js
CHANGED
|
@@ -11,6 +11,8 @@ the folder (the current folder by default), and checks them for risky
|
|
|
11
11
|
settings. Everything runs here. Nothing is sent anywhere unless you use --share.
|
|
12
12
|
|
|
13
13
|
Options
|
|
14
|
+
--explain Show everything each file tells your agents: rules,
|
|
15
|
+
permissions, MCP servers, hooks and hidden text
|
|
14
16
|
--share Publish this project's findings and print a link. Shows
|
|
15
17
|
what will be sent and asks first. No file contents are
|
|
16
18
|
sent, and nothing from outside the project.
|
|
@@ -26,7 +28,7 @@ Options
|
|
|
26
28
|
const LEVELS = ["critical", "high", "medium", "low"];
|
|
27
29
|
|
|
28
30
|
export async function main(argv) {
|
|
29
|
-
const opts = { dir: process.cwd(), share: false, yes: false, json: false, projectOnly: false, failOn: null };
|
|
31
|
+
const opts = { dir: process.cwd(), share: false, yes: false, json: false, explain: false, projectOnly: false, failOn: null };
|
|
30
32
|
for (let i = 0; i < argv.length; i++) {
|
|
31
33
|
const a = argv[i];
|
|
32
34
|
if (a === "-h" || a === "--help") {
|
|
@@ -40,6 +42,7 @@ export async function main(argv) {
|
|
|
40
42
|
if (a === "--share") opts.share = true;
|
|
41
43
|
else if (a === "--yes" || a === "-y") opts.yes = true;
|
|
42
44
|
else if (a === "--json") opts.json = true;
|
|
45
|
+
else if (a === "--explain") opts.explain = true;
|
|
43
46
|
else if (a === "--project-only") opts.projectOnly = true;
|
|
44
47
|
else if (a === "--fail-on" || a.startsWith("--fail-on=")) {
|
|
45
48
|
opts.failOn = (a.includes("=") ? a.split("=")[1] : argv[++i] ?? "").toLowerCase();
|
|
@@ -52,7 +55,7 @@ export async function main(argv) {
|
|
|
52
55
|
const result = check(input);
|
|
53
56
|
|
|
54
57
|
if (opts.json) process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
55
|
-
else printReport(result, { version: await version(), scanned: input.scanned });
|
|
58
|
+
else printReport(result, { version: await version(), scanned: input.scanned, explain: opts.explain });
|
|
56
59
|
|
|
57
60
|
if (opts.share) await share(opts, input, result);
|
|
58
61
|
|
package/lib/print.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Terminal output.
|
|
2
2
|
|
|
3
|
+
import { SCOPES } from "../engine/explain.js";
|
|
4
|
+
|
|
3
5
|
const env = process.env;
|
|
4
6
|
const color = Boolean(env.FORCE_COLOR) || (process.stdout.isTTY && !env.NO_COLOR && env.TERM !== "dumb");
|
|
5
7
|
const paint = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
@@ -33,7 +35,14 @@ function wrap(text, indent) {
|
|
|
33
35
|
|
|
34
36
|
const listText = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`);
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
// A list item whose wrapped lines line up under its text.
|
|
39
|
+
function bullet(text, indent) {
|
|
40
|
+
const lines = wrap(text, indent + 2).split("\n");
|
|
41
|
+
lines[0] = " ".repeat(indent) + "- " + lines[0].slice(indent + 2);
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function printReport(result, { version, scanned, explain = false }) {
|
|
37
46
|
const out = [];
|
|
38
47
|
const where = scanned.projectSkipped ? "your home folder" : scanned.project;
|
|
39
48
|
out.push(`${bold("misconfig")} ${dim(version)}`);
|
|
@@ -53,21 +62,20 @@ export function printReport(result, { version, scanned }) {
|
|
|
53
62
|
out.push(` ${counts.length ? counts.join(dim(", ")) : "No issues found"}`);
|
|
54
63
|
out.push("");
|
|
55
64
|
|
|
56
|
-
//
|
|
65
|
+
// Every file that directs an agent, where it applies, and what it tells the
|
|
66
|
+
// agent. Worked out on this computer; none of it is sent anywhere.
|
|
57
67
|
if (result.controlMap.length) {
|
|
58
|
-
out.push(bold("
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
shown.forEach((p, i) => out.push(` ${(i ? "" : agent).padEnd(pad)}${p}`));
|
|
70
|
-
if (paths.length > shown.length) out.push(` ${"".padEnd(pad)}${dim(`and ${paths.length - shown.length} more`)}`);
|
|
68
|
+
out.push(bold("What controls your agents"));
|
|
69
|
+
for (const scope of ["admin", "computer", "project", "loose"]) {
|
|
70
|
+
const files = result.controlMap.filter((f) => (f.scope ?? "project") === scope);
|
|
71
|
+
if (!files.length) continue;
|
|
72
|
+
out.push(` ${SCOPES[scope]}`);
|
|
73
|
+
for (const f of files) {
|
|
74
|
+
const agents = f.tools.filter((t) => t !== "Any agent started there").join(", ");
|
|
75
|
+
out.push(` ${bold(f.path)}${agents ? dim(` ${agents}`) : ""}`);
|
|
76
|
+
if (f.summary) out.push(wrap(f.summary, 6));
|
|
77
|
+
if (explain) for (const d of f.details ?? []) out.push(dim(bullet(d, 6)));
|
|
78
|
+
}
|
|
71
79
|
}
|
|
72
80
|
out.push("");
|
|
73
81
|
}
|
|
@@ -86,6 +94,7 @@ export function printReport(result, { version, scanned }) {
|
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
if (!result.findings.length) out.push(result.controlMap.length ? "No issues found in these files." : "No files that control AI agents were found.", "");
|
|
97
|
+
if (!explain && result.controlMap.some((f) => f.details?.length)) out.push(dim("Everything each file says: npx @misconfig/cli --explain"));
|
|
89
98
|
out.push(dim("Share this project's report: npx @misconfig/cli --share"));
|
|
90
99
|
out.push(dim("Full details as JSON: npx @misconfig/cli --json"));
|
|
91
100
|
process.stdout.write(out.join("\n") + "\n");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misconfig/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Finds every file that controls your AI coding agents and checks it for risky settings. Runs on your computer; nothing is uploaded unless you add --share.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|