@misconfig/cli 1.1.0 → 1.3.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/CHANGELOG.md +187 -0
- package/LICENSE +1 -0
- package/README.md +110 -30
- package/bin/misconfig.js +29 -1
- package/engine/catalog.js +504 -99
- package/engine/decode.js +41 -0
- package/engine/explain.js +792 -79
- package/engine/flags.js +121 -0
- package/engine/glob.js +178 -0
- package/engine/index.js +2108 -376
- package/engine/known.js +587 -0
- package/engine/locations.js +96 -49
- package/engine/mask.js +74 -21
- package/engine/named.js +91 -0
- package/engine/parse.js +442 -42
- package/engine/paths.js +83 -20
- package/lib/discover.js +675 -97
- package/lib/findings.js +109 -0
- package/lib/html.js +201 -0
- package/lib/lookup.js +209 -0
- package/lib/main.js +135 -39
- package/lib/print.js +223 -93
- package/package.json +22 -20
- package/report/fonts/OFL.txt +93 -0
- package/report/fonts/recursive-mono.woff2 +0 -0
- package/report/fonts/recursive-sans.woff2 +0 -0
- package/report/mark-black.svg +1 -0
- package/report/mark.svg +1 -0
- package/report/styles.css +2656 -0
package/engine/locations.js
CHANGED
|
@@ -3,21 +3,33 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Tokens: "~" is the home folder. "{config}" is the per-user app settings
|
|
5
5
|
// folder: ~/Library/Application Support on macOS, %APPDATA% on Windows and
|
|
6
|
-
// ~/.config on Linux. A path ending in "/" is a folder of files
|
|
7
|
-
|
|
8
|
-
export const OSES = { mac: "macOS", windows: "Windows", linux: "Linux" };
|
|
6
|
+
// ~/.config on Linux. A path ending in "/" is a folder of agent files, and
|
|
7
|
+
// "*" stands for any one folder or file name.
|
|
9
8
|
|
|
10
9
|
export const LOCATIONS = [
|
|
11
10
|
{
|
|
12
11
|
agent: "Claude Code",
|
|
13
|
-
controls: "Permissions, hooks, MCP servers, and every folder it has been started in",
|
|
14
|
-
user: [
|
|
12
|
+
controls: "Permissions, hooks, MCP servers, plugins, memory, and every folder it has been started in",
|
|
13
|
+
user: [
|
|
14
|
+
"~/.claude/settings.json",
|
|
15
|
+
"~/.claude/settings.local.json",
|
|
16
|
+
"~/.claude.json",
|
|
17
|
+
"~/.claude/CLAUDE.md",
|
|
18
|
+
"~/.claude/rules/",
|
|
19
|
+
"~/.claude/agents/",
|
|
20
|
+
"~/.claude/commands/",
|
|
21
|
+
"~/.claude/skills/",
|
|
22
|
+
"~/.claude/hooks/",
|
|
23
|
+
"~/.claude/projects/*/memory/MEMORY.md",
|
|
24
|
+
"~/.claude/plugins/installed_plugins.json",
|
|
25
|
+
"~/.claude/plugins/known_marketplaces.json",
|
|
26
|
+
],
|
|
15
27
|
system: {
|
|
16
|
-
mac: ["/Library/Application Support/ClaudeCode/managed-settings.json"],
|
|
17
|
-
windows: ["C:/
|
|
18
|
-
linux: ["/etc/claude-code/managed-settings.json"],
|
|
28
|
+
mac: ["/Library/Application Support/ClaudeCode/managed-settings.json", "/Library/Application Support/ClaudeCode/managed-settings.d/", "/Library/Application Support/ClaudeCode/managed-mcp.json"],
|
|
29
|
+
windows: ["C:/Program Files/ClaudeCode/managed-settings.json", "C:/Program Files/ClaudeCode/managed-settings.d/", "C:/Program Files/ClaudeCode/managed-mcp.json"],
|
|
30
|
+
linux: ["/etc/claude-code/managed-settings.json", "/etc/claude-code/managed-settings.d/", "/etc/claude-code/managed-mcp.json"],
|
|
19
31
|
},
|
|
20
|
-
project: ["CLAUDE.md", ".claude/settings.json", ".claude/settings.local.json", ".mcp.json", ".claude/agents/", ".claude/commands/"],
|
|
32
|
+
project: ["CLAUDE.md", ".claude/settings.json", ".claude/settings.local.json", ".mcp.json", ".claude/rules/", ".claude/agents/", ".claude/commands/", ".claude/skills/"],
|
|
21
33
|
},
|
|
22
34
|
{
|
|
23
35
|
agent: "Claude Desktop",
|
|
@@ -27,26 +39,32 @@ export const LOCATIONS = [
|
|
|
27
39
|
},
|
|
28
40
|
{
|
|
29
41
|
agent: "Codex",
|
|
30
|
-
controls: "Sandbox, approvals, MCP servers and trusted folders",
|
|
31
|
-
user: ["~/.codex/config.toml", "~/.codex/AGENTS.md"],
|
|
32
|
-
|
|
42
|
+
controls: "Sandbox, approvals, hooks, command rules, MCP servers, skills and trusted folders",
|
|
43
|
+
user: ["~/.codex/config.toml", "~/.codex/*.config.toml", "~/.codex/hooks.json", "~/.codex/rules/", "~/.codex/AGENTS.md", "~/.agents/skills/"],
|
|
44
|
+
system: { mac: ["/etc/codex/config.toml", "/etc/codex/requirements.toml"], linux: ["/etc/codex/config.toml", "/etc/codex/requirements.toml"] },
|
|
45
|
+
project: ["AGENTS.md", ".codex/config.toml", ".codex/hooks.json", ".codex/rules/", ".agents/skills/"],
|
|
33
46
|
},
|
|
34
47
|
{
|
|
35
|
-
agent: "
|
|
36
|
-
controls: "
|
|
37
|
-
user: ["
|
|
38
|
-
project: [".
|
|
48
|
+
agent: "GitHub Copilot",
|
|
49
|
+
controls: "Instructions, auto-approval, hooks, MCP servers and trusted folders, in VS Code and on the command line",
|
|
50
|
+
user: ["{config}/Code/User/settings.json", "{config}/Code/User/mcp.json", "~/.copilot/config.json", "~/.copilot/mcp-config.json"],
|
|
51
|
+
project: [".github/copilot-instructions.md", ".github/instructions/", ".github/prompts/", ".github/agents/", ".github/hooks/", ".github/mcp.json", ".vscode/settings.json", ".vscode/mcp.json", ".mcp.json", "AGENTS.md"],
|
|
39
52
|
},
|
|
40
53
|
{
|
|
41
|
-
agent: "
|
|
42
|
-
controls: "
|
|
43
|
-
user: ["
|
|
44
|
-
project: [".
|
|
54
|
+
agent: "Cursor",
|
|
55
|
+
controls: "Rules, hooks, sandbox, command permissions and MCP servers",
|
|
56
|
+
user: ["~/.cursor/mcp.json", "~/.cursor/hooks.json", "~/.cursor/cli-config.json", "~/.cursor/sandbox.json", "~/.cursor/permissions.json", "{config}/Cursor/User/settings.json"],
|
|
57
|
+
project: [".cursor/rules/", ".cursor/mcp.json", ".cursor/hooks.json", ".cursor/cli.json", ".cursorrules", "AGENTS.md"],
|
|
45
58
|
},
|
|
46
59
|
{
|
|
47
60
|
agent: "Gemini CLI",
|
|
48
|
-
controls: "
|
|
49
|
-
user: ["~/.gemini/settings.json", "~/.gemini/GEMINI.md"],
|
|
61
|
+
controls: "Approval mode, trusted folders, extensions, MCP servers and instructions",
|
|
62
|
+
user: ["~/.gemini/settings.json", "~/.gemini/GEMINI.md", "~/.gemini/trustedFolders.json", "~/.gemini/extensions/*/gemini-extension.json", "~/.gemini/extensions/*/GEMINI.md"],
|
|
63
|
+
system: {
|
|
64
|
+
mac: ["/Library/Application Support/GeminiCli/settings.json"],
|
|
65
|
+
windows: ["C:/ProgramData/gemini-cli/settings.json"],
|
|
66
|
+
linux: ["/etc/gemini-cli/settings.json"],
|
|
67
|
+
},
|
|
50
68
|
project: ["GEMINI.md", ".gemini/settings.json"],
|
|
51
69
|
},
|
|
52
70
|
{
|
|
@@ -55,33 +73,62 @@ export const LOCATIONS = [
|
|
|
55
73
|
user: {
|
|
56
74
|
mac: ["~/.zshrc", "~/.zprofile", "~/.bash_profile", "~/.bashrc"],
|
|
57
75
|
linux: ["~/.bashrc", "~/.zshrc", "~/.profile", "~/.config/fish/config.fish"],
|
|
58
|
-
windows: [
|
|
76
|
+
windows: [
|
|
77
|
+
"~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1",
|
|
78
|
+
"~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1",
|
|
79
|
+
"~/OneDrive*/Documents/PowerShell/Microsoft.PowerShell_profile.ps1",
|
|
80
|
+
"~/OneDrive*/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1",
|
|
81
|
+
],
|
|
59
82
|
},
|
|
60
83
|
project: [],
|
|
61
84
|
},
|
|
62
85
|
{
|
|
63
86
|
agent: "OpenCode",
|
|
64
|
-
controls: "Permissions, session sharing and MCP servers",
|
|
65
|
-
user: ["~/.config/opencode/opencode.json", "~/.config/opencode/AGENTS.md"],
|
|
87
|
+
controls: "Permissions, session sharing, plugins and MCP servers",
|
|
88
|
+
user: ["~/.config/opencode/opencode.json", "~/.config/opencode/AGENTS.md", "~/.config/opencode/plugins/"],
|
|
66
89
|
project: ["opencode.json", ".opencode/", "AGENTS.md"],
|
|
67
90
|
},
|
|
68
91
|
{
|
|
69
|
-
agent: "
|
|
70
|
-
controls: "
|
|
71
|
-
user: ["
|
|
72
|
-
project: [".
|
|
92
|
+
agent: "Cline",
|
|
93
|
+
controls: "Auto-approval, YOLO mode, MCP servers and rules",
|
|
94
|
+
user: ["{config}/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json", "~/.cline/data/settings/cline_mcp_settings.json", "~/.cline/data/globalState.json", "~/Documents/Cline/Rules/"],
|
|
95
|
+
project: [".clinerules", ".cline/plugins/"],
|
|
73
96
|
},
|
|
74
97
|
{
|
|
75
98
|
agent: "Windsurf",
|
|
76
|
-
controls: "Rules and MCP servers",
|
|
77
|
-
user: ["~/.codeium/windsurf/mcp_config.json", "{config}/Windsurf/User/settings.json"],
|
|
78
|
-
project: [".windsurf/rules/", ".windsurfrules"],
|
|
99
|
+
controls: "Rules, hooks and MCP servers",
|
|
100
|
+
user: ["~/.codeium/windsurf/mcp_config.json", "~/.codeium/windsurf/hooks.json", "{config}/Windsurf/User/settings.json"],
|
|
101
|
+
project: [".windsurf/rules/", ".windsurf/hooks.json", ".devin/hooks.v1.json", ".windsurfrules"],
|
|
79
102
|
},
|
|
80
103
|
{
|
|
81
|
-
agent: "
|
|
82
|
-
controls: "
|
|
83
|
-
user: ["
|
|
84
|
-
project: [".
|
|
104
|
+
agent: "Zed",
|
|
105
|
+
controls: "Agent tool permissions, trusted projects and context servers",
|
|
106
|
+
user: { mac: ["~/.config/zed/settings.json"], linux: ["~/.config/zed/settings.json"], windows: ["{config}/Zed/settings.json"] },
|
|
107
|
+
project: [".zed/settings.json"],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
agent: "Grok",
|
|
111
|
+
controls: "Permission mode, sandbox, hooks and MCP servers",
|
|
112
|
+
user: ["~/.grok/config.toml", "~/.grok/settings.json", "~/.grok/hooks/"],
|
|
113
|
+
project: [".grok/config.toml", ".grok/settings.json", ".grok/hooks/", ".grok/GROK.md"],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
agent: "Amp",
|
|
117
|
+
controls: "Permissions, plugins and MCP servers",
|
|
118
|
+
user: ["~/.config/amp/settings.json", "~/.config/amp/plugins/"],
|
|
119
|
+
project: [".amp/settings.json", ".amp/plugins/", "AGENTS.md"],
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
agent: "Goose",
|
|
123
|
+
controls: "Approval mode, extensions and hints",
|
|
124
|
+
user: { mac: ["~/.config/goose/config.yaml"], linux: ["~/.config/goose/config.yaml"], windows: ["{config}/Block/goose/config/config.yaml"] },
|
|
125
|
+
project: [".goosehints"],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
agent: "Continue",
|
|
129
|
+
controls: "Models, MCP servers, rules and where session data is sent",
|
|
130
|
+
user: ["~/.continue/config.yaml", "~/.continue/config.json"],
|
|
131
|
+
project: [".continue/"],
|
|
85
132
|
},
|
|
86
133
|
{
|
|
87
134
|
agent: "Roo Code",
|
|
@@ -89,23 +136,23 @@ export const LOCATIONS = [
|
|
|
89
136
|
user: ["{config}/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json"],
|
|
90
137
|
project: [".roo/", ".roomodes"],
|
|
91
138
|
},
|
|
92
|
-
{
|
|
93
|
-
agent: "Zed",
|
|
94
|
-
controls: "Agent tool approvals and context servers",
|
|
95
|
-
user: { mac: ["~/.config/zed/settings.json"], linux: ["~/.config/zed/settings.json"], windows: ["{config}/Zed/settings.json"] },
|
|
96
|
-
project: [".zed/settings.json"],
|
|
97
|
-
},
|
|
98
139
|
{
|
|
99
140
|
agent: "Kiro",
|
|
100
|
-
controls: "Steering files and MCP servers",
|
|
101
|
-
user: ["~/.kiro/settings/mcp.json", "~/.kiro/steering/"],
|
|
102
|
-
project: [".kiro/steering/", ".kiro/settings/mcp.json"],
|
|
141
|
+
controls: "Steering files, hooks, agents and MCP servers",
|
|
142
|
+
user: ["~/.kiro/settings/mcp.json", "~/.kiro/steering/", "~/.kiro/hooks/", "~/.kiro/agents/"],
|
|
143
|
+
project: [".kiro/steering/", ".kiro/settings/mcp.json", ".kiro/hooks/", ".kiro/agents/"],
|
|
103
144
|
},
|
|
104
145
|
{
|
|
105
146
|
agent: "Amazon Q",
|
|
106
|
-
controls: "Rules and MCP servers",
|
|
107
|
-
user: ["~/.aws/amazonq/mcp.json"],
|
|
108
|
-
project: [".amazonq/rules/", ".amazonq/mcp.json"],
|
|
147
|
+
controls: "Rules, agents and MCP servers",
|
|
148
|
+
user: ["~/.aws/amazonq/mcp.json", "~/.aws/amazonq/cli-agents/"],
|
|
149
|
+
project: [".amazonq/rules/", ".amazonq/mcp.json", ".amazonq/cli-agents/"],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
agent: "Junie",
|
|
153
|
+
controls: "Guidelines and MCP servers",
|
|
154
|
+
user: [],
|
|
155
|
+
project: [".junie/guidelines.md", ".junie/AGENTS.md", ".junie/mcp/mcp.json"],
|
|
109
156
|
},
|
|
110
157
|
{
|
|
111
158
|
agent: "Aider",
|
|
@@ -124,7 +171,7 @@ export function userPaths(entry, os) {
|
|
|
124
171
|
return [...list, ...system].map((p) => p.replace("{config}", CONFIG_DIR[os]));
|
|
125
172
|
}
|
|
126
173
|
|
|
127
|
-
// How to write a path so people
|
|
174
|
+
// How to write a path so people recognize it on their system.
|
|
128
175
|
export function displayPath(path, os) {
|
|
129
176
|
if (os !== "windows") return path;
|
|
130
177
|
return path
|
package/engine/mask.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
// Secret masking
|
|
1
|
+
// Secret masking. Likely secrets are replaced with «masked:<kind>:<length>» as
|
|
2
|
+
// files are read, before any check runs, so they never appear in results.
|
|
3
|
+
// Line breaks are kept, so line numbers still match the original file.
|
|
2
4
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// original file. The Worker runs the same masking again as a backstop.
|
|
5
|
+
// Every pattern here runs on untrusted files, so each one is written to take
|
|
6
|
+
// time in proportion to the text: no nested or adjacent open-ended repeats.
|
|
6
7
|
|
|
7
8
|
const MARK_OPEN = "«masked:";
|
|
8
9
|
|
|
10
|
+
const KEY_BEGIN = /-----BEGIN [A-Z0-9 ]{0,40}PRIVATE KEY-----/g;
|
|
11
|
+
const KEY_END = /-----END [A-Z0-9 ]{0,40}PRIVATE KEY-----/y;
|
|
12
|
+
|
|
13
|
+
// Patterns with a leading group keep that character: it stops a match from
|
|
14
|
+
// starting in the middle of a longer token.
|
|
9
15
|
const TOKEN_PATTERNS = [
|
|
10
|
-
["private-key", /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g],
|
|
11
16
|
["anthropic-key", /\bsk-ant-[A-Za-z0-9_-]{20,}/g],
|
|
12
17
|
["openai-key", /\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{20,}/g],
|
|
13
18
|
["github-token", /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})/g],
|
|
@@ -19,14 +24,18 @@ const TOKEN_PATTERNS = [
|
|
|
19
24
|
["groq-key", /\bgsk_[A-Za-z0-9]{20,}/g],
|
|
20
25
|
["huggingface-token", /\bhf_[A-Za-z0-9]{30,}/g],
|
|
21
26
|
["npm-token", /\bnpm_[A-Za-z0-9]{36}\b/g],
|
|
22
|
-
["jwt",
|
|
27
|
+
["jwt", /(^|[^A-Za-z0-9_-])(eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,})/g],
|
|
23
28
|
];
|
|
24
29
|
|
|
25
30
|
// key = value, "key": "value", KEY=value, --api-key value ...
|
|
26
31
|
const ASSIGNMENT =
|
|
27
|
-
/((?:api[_-]?key|apikey|access[_-]?key|secret[_-]?key|access[_-]?token|auth[_-]?token|refresh[_-]?token|client[_-]?secret|token|secret|password|passwd|pwd|private[_-]?key)["']
|
|
32
|
+
/((?:api[_-]?key|apikey|access[_-]?key|secret[_-]?key|access[_-]?token|auth[_-]?token|refresh[_-]?token|client[_-]?secret|token|secret|password|passwd|pwd|private[_-]?key)["']?(?:\s*[:=]\s*|\s+)["']?)([^\s"'`,;{}()<>[\]«»]{12,})/gi;
|
|
28
33
|
const BEARER = /(\bBearer\s+)([A-Za-z0-9._~+/=-]{16,})/g;
|
|
29
|
-
|
|
34
|
+
// The user name can be empty, as in redis://:password@host.
|
|
35
|
+
const URL_PASSWORD = /(\b[a-z][a-z0-9+.-]{0,30}:\/\/[^\s/:@"']{0,64}:)([^\s/@"']{6,})(?=@)/gi;
|
|
36
|
+
// Passwords are often short and plain, so a value named as one is masked from
|
|
37
|
+
// six characters: --password value, password: value, "DB_PASSWORD": "value".
|
|
38
|
+
const PASSWORD = /((?:--?(?:password|passwd|passphrase)[ \t]+|(?:password|passwd|passphrase)["']?[ \t]*[:=][ \t]*)["']?)([^\s"'`,;{}()<>[\]«»]{6,})/gi;
|
|
30
39
|
const URL_TOKEN = /([?&](?:token|key|api[_-]?key|apikey|access[_-]?token|auth|secret|sig|signature|password)=)([^&#\s"']{8,})/gi;
|
|
31
40
|
|
|
32
41
|
const PLACEHOLDER =
|
|
@@ -58,10 +67,7 @@ export function looksLikeSecret(value) {
|
|
|
58
67
|
const v = value.trim();
|
|
59
68
|
if (isMasked(v)) return true;
|
|
60
69
|
if (v.length < 12 || PLACEHOLDER.test(v)) return false;
|
|
61
|
-
|
|
62
|
-
re.lastIndex = 0;
|
|
63
|
-
if (re.test(v)) return true;
|
|
64
|
-
}
|
|
70
|
+
if (hasToken(v)) return true;
|
|
65
71
|
const classes = [/[a-z]/, /[A-Z]/, /[0-9]/, /[^A-Za-z0-9]/].filter((re) => re.test(v)).length;
|
|
66
72
|
return v.length >= 16 && classes >= 2 && entropy(v) >= 3.3 && !/\s/.test(v);
|
|
67
73
|
}
|
|
@@ -81,14 +87,45 @@ const WORDY = /^(?:[A-Za-z]+[0-9]{0,2}|[0-9]{1,4})$/;
|
|
|
81
87
|
export function looksLikeToken(value) {
|
|
82
88
|
if (typeof value !== "string") return false;
|
|
83
89
|
const v = value.trim();
|
|
84
|
-
if (isMasked(v)) return true;
|
|
90
|
+
if (isMasked(v) || hasToken(v)) return true;
|
|
91
|
+
if (!/[0-9]/.test(v) || !/[A-Za-z]/.test(v) || isPathLike(v)) return false;
|
|
92
|
+
// Names and versions, as in mcp-server-fetch==2025.4.7 or tool[cli]>=1.2.
|
|
93
|
+
if (v.split(/[-_.:@+=<>!~,[\]]/).every((part) => !part || WORDY.test(part))) return false;
|
|
94
|
+
return looksLikeSecret(v);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function hasToken(v) {
|
|
98
|
+
KEY_BEGIN.lastIndex = 0;
|
|
99
|
+
if (KEY_BEGIN.test(v)) return true;
|
|
85
100
|
for (const [, re] of TOKEN_PATTERNS) {
|
|
86
101
|
re.lastIndex = 0;
|
|
87
102
|
if (re.test(v)) return true;
|
|
88
103
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Private key blocks as [start, end] spans. Found with indexOf, so a file full
|
|
108
|
+
// of BEGIN lines without an END can't slow the check down.
|
|
109
|
+
function privateKeySpans(text) {
|
|
110
|
+
const spans = [];
|
|
111
|
+
KEY_BEGIN.lastIndex = 0;
|
|
112
|
+
for (let m = KEY_BEGIN.exec(text); m; m = KEY_BEGIN.exec(text)) {
|
|
113
|
+
let at = m.index + m[0].length;
|
|
114
|
+
let end = -1;
|
|
115
|
+
for (let i = text.indexOf("-----END ", at); i >= 0; i = text.indexOf("-----END ", at)) {
|
|
116
|
+
KEY_END.lastIndex = i;
|
|
117
|
+
const e = KEY_END.exec(text);
|
|
118
|
+
if (e) {
|
|
119
|
+
end = i + e[0].length;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
at = i + 9;
|
|
123
|
+
}
|
|
124
|
+
if (end < 0) break;
|
|
125
|
+
spans.push([m.index, end]);
|
|
126
|
+
KEY_BEGIN.lastIndex = end;
|
|
127
|
+
}
|
|
128
|
+
return spans;
|
|
92
129
|
}
|
|
93
130
|
|
|
94
131
|
export function maskSecrets(text) {
|
|
@@ -98,13 +135,28 @@ export function maskSecrets(text) {
|
|
|
98
135
|
count++;
|
|
99
136
|
kinds[kind] = (kinds[kind] || 0) + 1;
|
|
100
137
|
};
|
|
138
|
+
const hide = (kind, match) => {
|
|
139
|
+
note(kind);
|
|
140
|
+
const newlines = (match.match(/\n/g) || []).length;
|
|
141
|
+
return marker(kind, match.length) + "\n".repeat(newlines);
|
|
142
|
+
};
|
|
101
143
|
|
|
102
|
-
let out = text;
|
|
144
|
+
let out = String(text);
|
|
145
|
+
const spans = privateKeySpans(out);
|
|
146
|
+
if (spans.length) {
|
|
147
|
+
let rebuilt = "";
|
|
148
|
+
let last = 0;
|
|
149
|
+
for (const [start, end] of spans) {
|
|
150
|
+
rebuilt += out.slice(last, start) + hide("private-key", out.slice(start, end));
|
|
151
|
+
last = end;
|
|
152
|
+
}
|
|
153
|
+
out = rebuilt + out.slice(last);
|
|
154
|
+
}
|
|
103
155
|
for (const [kind, re] of TOKEN_PATTERNS) {
|
|
104
|
-
out = out.replace(re, (match) => {
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
return
|
|
156
|
+
out = out.replace(re, (match, ...groups) => {
|
|
157
|
+
if (typeof groups[0] !== "string") return hide(kind, match);
|
|
158
|
+
const [lead, token] = groups;
|
|
159
|
+
return lead + hide(kind, token);
|
|
108
160
|
});
|
|
109
161
|
}
|
|
110
162
|
const keepPrefix = (kind) => (match, prefix, value) => {
|
|
@@ -114,6 +166,7 @@ export function maskSecrets(text) {
|
|
|
114
166
|
return prefix + marker(kind, value.length);
|
|
115
167
|
};
|
|
116
168
|
out = out.replace(URL_PASSWORD, keepPrefix("url-password"));
|
|
169
|
+
out = out.replace(PASSWORD, keepPrefix("password"));
|
|
117
170
|
out = out.replace(URL_TOKEN, keepPrefix("url-token"));
|
|
118
171
|
out = out.replace(BEARER, keepPrefix("bearer-token"));
|
|
119
172
|
out = out.replace(ASSIGNMENT, keepPrefix("assigned-secret"));
|
package/engine/named.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Files that settings name as instructions for an agent, beyond the usual
|
|
2
|
+
// names: Gemini CLI's context file names, Codex's fallback names for
|
|
3
|
+
// AGENTS.md, OpenCode's instructions list and Aider's read list. A project
|
|
4
|
+
// can use them to keep its instructions in a file the usual names don't
|
|
5
|
+
// cover, so the command and the checks both read them as instructions.
|
|
6
|
+
|
|
7
|
+
import { parseJSONC, parseTOML, parseYAML } from "./parse.js";
|
|
8
|
+
import { globMatch } from "./glob.js";
|
|
9
|
+
|
|
10
|
+
const names = (v) =>
|
|
11
|
+
(typeof v === "string" ? [v] : Array.isArray(v) ? v.filter((x) => typeof x === "string") : [])
|
|
12
|
+
.map((x) => x.trim())
|
|
13
|
+
.filter((x) => x && x.length <= 300)
|
|
14
|
+
.slice(0, 50);
|
|
15
|
+
|
|
16
|
+
// For each settings file: where it is, the agent, how to read it, the names
|
|
17
|
+
// it gives, and whether a name is a file name found anywhere ("name"), or a
|
|
18
|
+
// path or glob from the top of the project ("path").
|
|
19
|
+
const SOURCES = [
|
|
20
|
+
{ re: /(^|\/)\.gemini\/settings\.json$/i, tool: "Gemini CLI", parse: parseJSONC, list: (j) => names(j?.context?.fileName ?? j?.contextFileName), match: "name" },
|
|
21
|
+
{ re: /(^|\/)\.codex\/config\.toml$/i, tool: "Codex", parse: parseTOML, list: (t) => names(t?.project_doc_fallback_filenames), match: "name" },
|
|
22
|
+
{ re: /^(?:\.opencode\/)?opencode\.jsonc?$/i, tool: "OpenCode", parse: parseJSONC, list: (j) => names(j?.instructions), match: "path" },
|
|
23
|
+
{ re: /(^|\/)\.aider\.conf\.ya?ml$/i, tool: "Aider", parse: parseYAML, list: (y) => names(y?.read), match: "path" },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export const NAMING_SETTINGS = SOURCES.map((s) => s.re);
|
|
27
|
+
|
|
28
|
+
// A name that points out of the project, or to a web address.
|
|
29
|
+
export const outsideName = (name) => /^(?:~|\/|[A-Za-z]:|\\\\)/.test(name) || /(^|[\\/])\.\.([\\/]|$)/.test(name);
|
|
30
|
+
export const webName = (name) => /^https?:\/\//i.test(name);
|
|
31
|
+
|
|
32
|
+
// What the settings files given as { path, content } name:
|
|
33
|
+
// [{ tool, from, name, outside, web, test(path) }].
|
|
34
|
+
export function namedInstructions(files) {
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const f of Array.isArray(files) ? files : []) {
|
|
37
|
+
if (typeof f?.path !== "string" || typeof f.content !== "string") continue;
|
|
38
|
+
const source = SOURCES.find((s) => s.re.test(f.path));
|
|
39
|
+
if (!source) continue;
|
|
40
|
+
let value;
|
|
41
|
+
try {
|
|
42
|
+
value = source.parse(f.content);
|
|
43
|
+
} catch {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
for (const name of source.list(value)) {
|
|
47
|
+
const plain = name.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
48
|
+
const outside = outsideName(name);
|
|
49
|
+
const web = webName(name);
|
|
50
|
+
const test =
|
|
51
|
+
outside || web
|
|
52
|
+
? () => false
|
|
53
|
+
: source.match === "name"
|
|
54
|
+
? (path) => path.split("/").pop().toLowerCase() === plain.split("/").pop().toLowerCase()
|
|
55
|
+
: (path) => path.toLowerCase() === plain.toLowerCase() || (/[*?[]/.test(plain) && globMatch(plain, path));
|
|
56
|
+
out.push({ tool: source.tool, from: f.path, name, outside, web, test });
|
|
57
|
+
if (out.length >= 200) return out;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The entries a collector found that the names pick out, without testing
|
|
64
|
+
// every name against every file: a name is looked up, an exact path too, and
|
|
65
|
+
// globs are tried only on text files. `pathOf` gives an entry's project path.
|
|
66
|
+
const TEXT = /\.(?:md|mdc|markdown|txt|rst|adoc)$/i;
|
|
67
|
+
export function pickNamed(named, entries, pathOf) {
|
|
68
|
+
if (!named.length) return [];
|
|
69
|
+
const byName = new Map();
|
|
70
|
+
const byPath = new Map();
|
|
71
|
+
for (const e of entries) {
|
|
72
|
+
const p = pathOf(e);
|
|
73
|
+
const base = p.split("/").pop().toLowerCase();
|
|
74
|
+
if (!byName.has(base)) byName.set(base, []);
|
|
75
|
+
byName.get(base).push(e);
|
|
76
|
+
byPath.set(p.toLowerCase(), e);
|
|
77
|
+
}
|
|
78
|
+
const picked = new Set();
|
|
79
|
+
for (const n of named.filter((x) => !x.outside && !x.web)) {
|
|
80
|
+
const plain = n.name.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
81
|
+
if (/[*?[]/.test(plain)) {
|
|
82
|
+
for (const e of entries) if (TEXT.test(pathOf(e)) && n.test(pathOf(e))) picked.add(e);
|
|
83
|
+
} else {
|
|
84
|
+
for (const e of byName.get(plain.split("/").pop().toLowerCase()) ?? []) if (n.test(pathOf(e))) picked.add(e);
|
|
85
|
+
const exact = byPath.get(plain.toLowerCase());
|
|
86
|
+
if (exact && n.test(pathOf(exact))) picked.add(exact);
|
|
87
|
+
}
|
|
88
|
+
if (picked.size >= 50) break;
|
|
89
|
+
}
|
|
90
|
+
return [...picked];
|
|
91
|
+
}
|