coldpin 0.0.0-stage → 1.5.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/ACCESSIBILITY.md +17 -0
- package/CHANGELOG.md +97 -0
- package/CONTRIBUTING.md +36 -0
- package/LICENSE +98 -0
- package/MAINTENANCE.md +33 -0
- package/README.md +142 -2
- package/SECURITY.md +34 -0
- package/TESTING.md +26 -0
- package/agents/coldpin-auditor.md +47 -0
- package/agents/coldpin-compliance.md +38 -0
- package/agents/coldpin-confusion-auditor.md +38 -0
- package/agents/coldpin-discoverer.md +37 -0
- package/agents/coldpin-forensics.md +38 -0
- package/agents/coldpin-inspector.md +37 -0
- package/agents/coldpin-manifest-auditor.md +38 -0
- package/assets/icon.svg +7 -0
- package/catalog/mcp-schema-pin.json +14 -0
- package/catalog/plugin.oms.sig +19 -0
- package/catalog/sigma/npx-suspicious-child-process-linux.yml +54 -0
- package/catalog/sigma/npx-suspicious-child-process.yml +49 -0
- package/catalog/triage-rules.json +104 -0
- package/docs/assets/readme-header.svg +21 -0
- package/docs/designs/SITEMAP.md +14 -0
- package/docs/designs/coldpin.md +68 -0
- package/docs/fact-ledger.md +36 -0
- package/docs/faq.md +31 -0
- package/docs/getting_started.md +62 -0
- package/docs/harnesses.md +45 -0
- package/docs/privacy.md +27 -0
- package/docs/verification/skill-inspector-self-audit.md +33 -0
- package/examples/.coldpin.policy.example.json +27 -0
- package/examples/.npmrc.example +8 -0
- package/examples/mcp_config.private-registry.example.json +42 -0
- package/hooks.json +47 -0
- package/lib/analysis/parity-and-bisect.mjs +1371 -0
- package/lib/analysis/static-triage.mjs +4572 -0
- package/lib/cache/sqlite-store.mjs +251 -0
- package/lib/cli.mjs +427 -0
- package/lib/compliance/audit-log.mjs +357 -0
- package/lib/config/policy.mjs +780 -0
- package/lib/core/path-confinement.mjs +289 -0
- package/lib/core/workflows.mjs +1205 -0
- package/lib/discovery/slopsquat-guard.mjs +289 -0
- package/lib/hook.mjs +1038 -0
- package/lib/intel/registry-osv.mjs +1681 -0
- package/lib/mcp/report-store.mjs +175 -0
- package/lib/mcp/server.mjs +1387 -0
- package/lib/mcp/stdio-transport.mjs +289 -0
- package/lib/mcp/tool-catalog.mjs +273 -0
- package/lib/mcp/types.mjs +95 -0
- package/lib/mcp.mjs +19 -0
- package/lib/quarantine/safe-unpack.mjs +568 -0
- package/lib/types.mjs +383 -0
- package/lib/verdict/engine-and-formatters.mjs +895 -0
- package/mcp_config.json +21 -0
- package/package.json +71 -3
- package/plugin.json +54 -0
- package/rules/AGENTS.md +18 -0
- package/rules/coldpin-incident-checklist.md +18 -0
- package/rules/coldpin-manifest-guard.md +14 -0
- package/server.json +38 -0
- package/skills/coldpin/BENCHMARK.md +166 -0
- package/skills/coldpin/SKILL.md +110 -0
- package/skills/coldpin/TEST.md +13 -0
- package/skills/coldpin/agents/openai.yaml +6 -0
- package/skills/coldpin/assets/icon.svg +7 -0
- package/skills/coldpin/assets/runtime-contract.yaml +105 -0
- package/skills/coldpin/evals/evals.json +60 -0
- package/skills/coldpin/references/aspect-compliance-audit.md +27 -0
- package/skills/coldpin/references/aspect-discovery.md +26 -0
- package/skills/coldpin/references/aspect-forensics-rea.md +26 -0
- package/skills/coldpin/references/aspect-inspection.md +26 -0
- package/skills/coldpin/references/aspect-manifest-confusion.md +26 -0
- package/skills/coldpin/references/enterprise-policy-schema.md +65 -0
- package/skills/coldpin/references/evidence-card-spec.md +27 -0
- package/skills/coldpin/references/rea-integration-playbook.md +34 -0
- package/skills/coldpin/references/threat-taxonomy.md +35 -0
- package/skills/coldpin/skill-card.md +62 -0
- package/skills/coldpin/skill.oms.sig +19 -0
- package/skills/coldpin/test_scenarios.yaml +61 -0
- package/skills/coldpin-audit/SKILL.md +39 -0
- package/skills/coldpin-incident/SKILL.md +37 -0
- package/src/analysis/parity-and-bisect.ts +1368 -0
- package/src/analysis/static-triage.ts +4569 -0
- package/src/cache/sqlite-store.ts +248 -0
- package/src/cli.ts +424 -0
- package/src/compliance/audit-log.ts +354 -0
- package/src/config/policy.ts +777 -0
- package/src/core/path-confinement.ts +286 -0
- package/src/core/workflows.ts +1202 -0
- package/src/discovery/slopsquat-guard.ts +286 -0
- package/src/hook.ts +1035 -0
- package/src/intel/registry-osv.ts +1678 -0
- package/src/mcp/report-store.ts +172 -0
- package/src/mcp/server.ts +1384 -0
- package/src/mcp/stdio-transport.ts +286 -0
- package/src/mcp/tool-catalog.ts +270 -0
- package/src/mcp/types.ts +92 -0
- package/src/mcp.ts +16 -0
- package/src/quarantine/safe-unpack.ts +565 -0
- package/src/types.ts +380 -0
- package/src/verdict/engine-and-formatters.ts +892 -0
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { readCappedRegularFileSync } from "../core/path-confinement.mjs";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
const MAX_POLICY_BYTES = 1024 * 1024;
|
|
12
|
+
const MAX_NPMRC_BYTES = 512 * 1024;
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_POLICY = {
|
|
15
|
+
private_scopes: [],
|
|
16
|
+
private_prefixes: [],
|
|
17
|
+
private_registries: {},
|
|
18
|
+
default_registry: "https://registry.npmjs.org",
|
|
19
|
+
osv_api_url: "https://api.osv.dev",
|
|
20
|
+
allow_public_fallback: false,
|
|
21
|
+
allowed_orgs: [],
|
|
22
|
+
denied_orgs: [],
|
|
23
|
+
blocked_licenses: ["AGPL-3.0", "AGPL-3.0-only", "SSPL-1.0"],
|
|
24
|
+
cooldown_hours: 72,
|
|
25
|
+
max_compressed_bytes: 20 * 1024 * 1024,
|
|
26
|
+
max_uncompressed_bytes: 50 * 1024 * 1024,
|
|
27
|
+
max_files: 5000,
|
|
28
|
+
max_single_file_bytes: 10 * 1024 * 1024,
|
|
29
|
+
block_on_kev: true,
|
|
30
|
+
block_on_critical_cve: true,
|
|
31
|
+
block_on_high_cve: false,
|
|
32
|
+
require_provenance: false,
|
|
33
|
+
require_source_link: false,
|
|
34
|
+
bisect_max_commits: 200,
|
|
35
|
+
bisect_max_days: 180,
|
|
36
|
+
intel_ttl_seconds: 21600,
|
|
37
|
+
offline_mode: false,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const PUBLIC_NPM_HOSTS = new Set(["registry.npmjs.org", "registry.yarnpkg.com"]);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Unanchored Antigravity placeholder detector (`[PLG-09]`):
|
|
59
|
+
* Rejects literal unexpanded placeholders such as `${COLDPIN_REGISTRY_TOKEN}`,
|
|
60
|
+
* `${PLUGIN_DATA}/cache`, or `Bearer ${TOKEN}` if a host enables a plugin before filling variables.
|
|
61
|
+
*/
|
|
62
|
+
export const UNEXPANDED_PLACEHOLDER_RE = /\$\{[A-Za-z0-9_]+\}/;
|
|
63
|
+
|
|
64
|
+
export function hasUnexpandedPlaceholder(raw ) {
|
|
65
|
+
return typeof raw === "string" && UNEXPANDED_PLACEHOLDER_RE.test(raw);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function sanitizeOperatorEnvValue(raw ) {
|
|
69
|
+
if (typeof raw !== "string") return undefined;
|
|
70
|
+
const trimmed = raw.trim();
|
|
71
|
+
if (!trimmed || hasUnexpandedPlaceholder(trimmed)) return undefined;
|
|
72
|
+
return trimmed;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function isValidPrivateRegistryEnvUrl(rawUrl ) {
|
|
76
|
+
if (hasUnexpandedPlaceholder(rawUrl)) return false;
|
|
77
|
+
let parsed ;
|
|
78
|
+
try {
|
|
79
|
+
parsed = new URL(rawUrl);
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (parsed.protocol !== "https:") return false;
|
|
84
|
+
if (parsed.username || parsed.password) return false;
|
|
85
|
+
const host = parsed.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
86
|
+
if (!host || PUBLIC_NPM_HOSTS.has(host)) return false;
|
|
87
|
+
if (
|
|
88
|
+
host === "localhost" ||
|
|
89
|
+
host.endsWith(".localhost") ||
|
|
90
|
+
host === "metadata.google.internal" ||
|
|
91
|
+
host === "metadata.goog" ||
|
|
92
|
+
host === "169.254.169.254" ||
|
|
93
|
+
host === "100.100.100.200" ||
|
|
94
|
+
host === "fd00:ec2::254" ||
|
|
95
|
+
host === "::1" ||
|
|
96
|
+
host === "::" ||
|
|
97
|
+
host.startsWith("127.") ||
|
|
98
|
+
host.startsWith("0.") ||
|
|
99
|
+
host.startsWith("169.254.") ||
|
|
100
|
+
/^fe[89ab][0-9a-f]:/.test(host) ||
|
|
101
|
+
host.startsWith("::ffff:127.") ||
|
|
102
|
+
host.startsWith("::ffff:169.254.") ||
|
|
103
|
+
host.startsWith("::ffff:0.")
|
|
104
|
+
) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function applyPrivateRegistryEnvOverlay(
|
|
111
|
+
policy ,
|
|
112
|
+
hasExplicitPolicyFile ,
|
|
113
|
+
env = process.env,
|
|
114
|
+
) {
|
|
115
|
+
const rawScopes = sanitizeOperatorEnvValue(env["COLDPIN_PRIVATE_SCOPES"]);
|
|
116
|
+
const rawRegUrl = sanitizeOperatorEnvValue(env["COLDPIN_PRIVATE_REGISTRY_URL"]);
|
|
117
|
+
if (!rawScopes && !rawRegUrl) return policy;
|
|
118
|
+
|
|
119
|
+
const envScopes = rawScopes
|
|
120
|
+
? rawScopes
|
|
121
|
+
.split(",")
|
|
122
|
+
.map((s) => s.trim().toLowerCase())
|
|
123
|
+
.filter(Boolean)
|
|
124
|
+
.map((s) => (s.startsWith("@") ? s : `@${s}`))
|
|
125
|
+
: [];
|
|
126
|
+
const validRegUrl = rawRegUrl && isValidPrivateRegistryEnvUrl(rawRegUrl) ? rawRegUrl.replace(/\/+$/, "") : undefined;
|
|
127
|
+
|
|
128
|
+
const privateScopes = Array.from(new Set([...policy.private_scopes, ...envScopes]));
|
|
129
|
+
const privateRegistries = { ...policy.private_registries };
|
|
130
|
+
if (validRegUrl) {
|
|
131
|
+
for (const scope of envScopes) {
|
|
132
|
+
if (!hasExplicitPolicyFile || !privateRegistries[scope]) {
|
|
133
|
+
privateRegistries[scope] = validRegUrl;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...policy,
|
|
139
|
+
private_scopes: privateScopes,
|
|
140
|
+
private_registries: privateRegistries,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const SECRET_LIKE_PATTERNS = [
|
|
145
|
+
/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{16,}\b/,
|
|
146
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}\b/,
|
|
147
|
+
/\bnpm_[A-Za-z0-9]{20,}\b/,
|
|
148
|
+
/\b(?:AKIA|ASIA|ABIA|ACCA)[0-9A-Z]{16}\b/,
|
|
149
|
+
/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/,
|
|
150
|
+
/\bsk-(?:proj-|live-|test-)?[A-Za-z0-9_-]{20,}\b/,
|
|
151
|
+
/\bAIza[0-9A-Za-z_-]{25,}\b/,
|
|
152
|
+
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{8,}\b/,
|
|
153
|
+
/-----BEGIN\s+(?:RSA\s+|EC\s+|OPENSSH\s+)?PRIVATE\s+KEY-----/i,
|
|
154
|
+
/\b(?:api[_-]?key|secret|password|passwd|bearer|auth[_-]?token)\s*[:=]\s*[^\s]{6,}/i,
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
export function hasSecretLikeDiscoveryToken(raw ) {
|
|
158
|
+
if (!raw) return false;
|
|
159
|
+
for (const re of SECRET_LIKE_PATTERNS) {
|
|
160
|
+
if (re.test(raw)) return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function isPublicNpmRegistryUrl(rawUrl ) {
|
|
166
|
+
try {
|
|
167
|
+
const host = new URL(rawUrl).hostname.toLowerCase();
|
|
168
|
+
return PUBLIC_NPM_HOSTS.has(host);
|
|
169
|
+
} catch {
|
|
170
|
+
return rawUrl.toLowerCase().includes("registry.npmjs.org");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function levenshtein(a , b ) {
|
|
175
|
+
const m = a.length;
|
|
176
|
+
const n = b.length;
|
|
177
|
+
if (m === 0) return n;
|
|
178
|
+
if (n === 0) return m;
|
|
179
|
+
let prev = new Array (n + 1);
|
|
180
|
+
let curr = new Array (n + 1);
|
|
181
|
+
for (let j = 0; j <= n; j++) prev[j] = j;
|
|
182
|
+
for (let i = 1; i <= m; i++) {
|
|
183
|
+
curr[0] = i;
|
|
184
|
+
const ca = a.charCodeAt(i - 1);
|
|
185
|
+
for (let j = 1; j <= n; j++) {
|
|
186
|
+
const cost = ca === b.charCodeAt(j - 1) ? 0 : 1;
|
|
187
|
+
const del = (prev[j] ?? 0) + 1;
|
|
188
|
+
const ins = (curr[j - 1] ?? 0) + 1;
|
|
189
|
+
const sub = (prev[j - 1] ?? 0) + cost;
|
|
190
|
+
curr[j] = Math.min(del, ins, sub);
|
|
191
|
+
}
|
|
192
|
+
const tmp = prev;
|
|
193
|
+
prev = curr;
|
|
194
|
+
curr = tmp;
|
|
195
|
+
}
|
|
196
|
+
return prev[n] ?? 0;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function findGitRoot(startDir ) {
|
|
200
|
+
let dir = resolve(startDir);
|
|
201
|
+
for (let i = 0; i < 32; i++) {
|
|
202
|
+
if (existsSync(join(dir, ".git"))) return dir;
|
|
203
|
+
const parent = dirname(dir);
|
|
204
|
+
if (parent === dir) break;
|
|
205
|
+
dir = parent;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function asStringArray(val , fallback ) {
|
|
211
|
+
if (!Array.isArray(val)) return fallback;
|
|
212
|
+
return val.filter((v) => typeof v === "string");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function asStringRecord(val , fallback ) {
|
|
216
|
+
if (val === null || typeof val !== "object" || Array.isArray(val)) return fallback;
|
|
217
|
+
const out = {};
|
|
218
|
+
for (const [k, v] of Object.entries(val )) {
|
|
219
|
+
if (typeof v === "string") out[k] = v;
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function asPositiveNumber(val , fallback ) {
|
|
225
|
+
return typeof val === "number" && Number.isFinite(val) && val >= 0 ? val : fallback;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function asBoolean(val , fallback ) {
|
|
229
|
+
return typeof val === "boolean" ? val : fallback;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function parseRawPolicyObject(raw , base = DEFAULT_POLICY) {
|
|
233
|
+
const normalizedPrivateRegistries = {};
|
|
234
|
+
for (const [k, v] of Object.entries(asStringRecord(raw["private_registries"], base.private_registries))) {
|
|
235
|
+
const scopeKey = k.startsWith("@") ? k.toLowerCase() : `@${k.toLowerCase()}`;
|
|
236
|
+
normalizedPrivateRegistries[scopeKey] = v.replace(/\/+$/, "");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
private_scopes: asStringArray(raw["private_scopes"], base.private_scopes).map((s) =>
|
|
241
|
+
s.startsWith("@") ? s.toLowerCase() : `@${s.toLowerCase()}`,
|
|
242
|
+
),
|
|
243
|
+
private_prefixes: asStringArray(raw["private_prefixes"], base.private_prefixes).map((s) => s.toLowerCase()),
|
|
244
|
+
private_registries: normalizedPrivateRegistries,
|
|
245
|
+
default_registry: typeof raw["default_registry"] === "string" ? raw["default_registry"] : base.default_registry,
|
|
246
|
+
osv_api_url:
|
|
247
|
+
typeof raw["osv_api_url"] === "string" && raw["osv_api_url"].trim().length > 0
|
|
248
|
+
? raw["osv_api_url"].trim().replace(/\/+$/, "")
|
|
249
|
+
: base.osv_api_url,
|
|
250
|
+
allow_public_fallback: asBoolean(raw["allow_public_fallback"], base.allow_public_fallback),
|
|
251
|
+
allowed_orgs: asStringArray(raw["allowed_orgs"], base.allowed_orgs).map((s) => s.toLowerCase()),
|
|
252
|
+
denied_orgs: asStringArray(raw["denied_orgs"], base.denied_orgs).map((s) => s.toLowerCase()),
|
|
253
|
+
blocked_licenses: asStringArray(raw["blocked_licenses"], base.blocked_licenses),
|
|
254
|
+
cooldown_hours: asPositiveNumber(raw["cooldown_hours"], base.cooldown_hours),
|
|
255
|
+
max_compressed_bytes: asPositiveNumber(raw["max_compressed_bytes"], base.max_compressed_bytes),
|
|
256
|
+
max_uncompressed_bytes: asPositiveNumber(raw["max_uncompressed_bytes"], base.max_uncompressed_bytes),
|
|
257
|
+
max_files: asPositiveNumber(raw["max_files"], base.max_files),
|
|
258
|
+
max_single_file_bytes: asPositiveNumber(raw["max_single_file_bytes"], base.max_single_file_bytes),
|
|
259
|
+
block_on_kev: asBoolean(raw["block_on_kev"], base.block_on_kev),
|
|
260
|
+
block_on_critical_cve: asBoolean(raw["block_on_critical_cve"], base.block_on_critical_cve),
|
|
261
|
+
block_on_high_cve: asBoolean(raw["block_on_high_cve"], base.block_on_high_cve),
|
|
262
|
+
require_provenance: asBoolean(raw["require_provenance"], base.require_provenance),
|
|
263
|
+
require_source_link: asBoolean(raw["require_source_link"], base.require_source_link),
|
|
264
|
+
bisect_max_commits: asPositiveNumber(raw["bisect_max_commits"], base.bisect_max_commits),
|
|
265
|
+
bisect_max_days: asPositiveNumber(raw["bisect_max_days"], base.bisect_max_days),
|
|
266
|
+
intel_ttl_seconds: asPositiveNumber(raw["intel_ttl_seconds"], base.intel_ttl_seconds),
|
|
267
|
+
offline_mode: asBoolean(raw["offline_mode"], base.offline_mode),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function readPolicyJsonFile(filePath ) {
|
|
272
|
+
const content = readCappedRegularFileSync(filePath, MAX_POLICY_BYTES).toString("utf8");
|
|
273
|
+
const parsed = JSON.parse(content);
|
|
274
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
275
|
+
throw new Error(`Invalid policy JSON object in ${filePath}`);
|
|
276
|
+
}
|
|
277
|
+
return parsed ;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function mergePolicyAdditiveTighteningOnly(base , ws ) {
|
|
281
|
+
const unionLower = (a , b ) =>
|
|
282
|
+
Array.from(new Set([...a.map((x) => x.toLowerCase()), ...b.map((x) => x.toLowerCase())]));
|
|
283
|
+
const unionExact = (a , b ) => Array.from(new Set([...a, ...b]));
|
|
284
|
+
return {
|
|
285
|
+
// Workspace policy may ADD private scopes/prefixes, denied orgs, and blocked licenses
|
|
286
|
+
private_scopes: unionLower(base.private_scopes, ws.private_scopes),
|
|
287
|
+
private_prefixes: unionLower(base.private_prefixes, ws.private_prefixes),
|
|
288
|
+
// Never allow untrusted workspace policy to redirect registries, OSV endpoints, or public fallback
|
|
289
|
+
private_registries: { ...base.private_registries },
|
|
290
|
+
default_registry: base.default_registry,
|
|
291
|
+
osv_api_url: base.osv_api_url,
|
|
292
|
+
allow_public_fallback: base.allow_public_fallback && ws.allow_public_fallback,
|
|
293
|
+
// Allowed orgs may only narrow (never widen)
|
|
294
|
+
allowed_orgs:
|
|
295
|
+
base.allowed_orgs.length > 0 && ws.allowed_orgs.length > 0
|
|
296
|
+
? base.allowed_orgs.filter((o) => ws.allowed_orgs.includes(o))
|
|
297
|
+
: base.allowed_orgs.length > 0
|
|
298
|
+
? [...base.allowed_orgs]
|
|
299
|
+
: [...ws.allowed_orgs],
|
|
300
|
+
denied_orgs: unionLower(base.denied_orgs, ws.denied_orgs),
|
|
301
|
+
blocked_licenses: unionExact(base.blocked_licenses, ws.blocked_licenses),
|
|
302
|
+
// Thresholds & resource caps may only tighten
|
|
303
|
+
cooldown_hours: Math.max(base.cooldown_hours, ws.cooldown_hours),
|
|
304
|
+
max_compressed_bytes: Math.min(base.max_compressed_bytes, ws.max_compressed_bytes),
|
|
305
|
+
max_uncompressed_bytes: Math.min(base.max_uncompressed_bytes, ws.max_uncompressed_bytes),
|
|
306
|
+
max_files: Math.min(base.max_files, ws.max_files),
|
|
307
|
+
max_single_file_bytes: Math.min(base.max_single_file_bytes, ws.max_single_file_bytes),
|
|
308
|
+
// Security gates may only tighten (false -> true)
|
|
309
|
+
block_on_kev: base.block_on_kev || ws.block_on_kev,
|
|
310
|
+
block_on_critical_cve: base.block_on_critical_cve || ws.block_on_critical_cve,
|
|
311
|
+
block_on_high_cve: base.block_on_high_cve || ws.block_on_high_cve,
|
|
312
|
+
require_provenance: base.require_provenance || ws.require_provenance,
|
|
313
|
+
require_source_link: base.require_source_link || ws.require_source_link,
|
|
314
|
+
bisect_max_commits: Math.min(base.bisect_max_commits, ws.bisect_max_commits),
|
|
315
|
+
bisect_max_days: Math.min(base.bisect_max_days, ws.bisect_max_days),
|
|
316
|
+
intel_ttl_seconds: Math.min(base.intel_ttl_seconds, ws.intel_ttl_seconds),
|
|
317
|
+
offline_mode: base.offline_mode || ws.offline_mode,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function loadPolicy(cwd , explicitPath )
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
{
|
|
326
|
+
const candidates = [];
|
|
327
|
+
if (explicitPath) {
|
|
328
|
+
candidates.push(resolve(explicitPath));
|
|
329
|
+
} else {
|
|
330
|
+
const policyFiles = [".coldpin.policy.json", ".npx-guard.policy.json"];
|
|
331
|
+
const resolvedCwd = resolve(cwd);
|
|
332
|
+
const gitRoot = findGitRoot(cwd);
|
|
333
|
+
for (const fileName of policyFiles) {
|
|
334
|
+
candidates.push(join(resolvedCwd, fileName));
|
|
335
|
+
if (gitRoot && gitRoot !== resolvedCwd) {
|
|
336
|
+
candidates.push(join(gitRoot, fileName));
|
|
337
|
+
}
|
|
338
|
+
candidates.push(join(homedir(), fileName));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
let loadedPath = null;
|
|
343
|
+
let raw = {};
|
|
344
|
+
for (const p of candidates) {
|
|
345
|
+
if (existsSync(p)) {
|
|
346
|
+
raw = readPolicyJsonFile(p);
|
|
347
|
+
loadedPath = p;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const parsedPolicy = parseRawPolicyObject(raw, DEFAULT_POLICY);
|
|
353
|
+
const policy = applyPrivateRegistryEnvOverlay(parsedPolicy, Boolean(explicitPath && loadedPath));
|
|
354
|
+
const policy_sha256 = createHash("sha256").update(JSON.stringify(policy)).digest("hex");
|
|
355
|
+
return { policy, policy_path: loadedPath, policy_sha256 };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Operator-controlled MCP policy loader (`[MCP-01]`):
|
|
360
|
+
* Loads base policy strictly from `COLDPIN_POLICY_PATH` -> `~/.coldpin.policy.json` -> `DEFAULT_POLICY`.
|
|
361
|
+
* Untrusted workspace `.coldpin.policy.json` files can ONLY apply additive tightening unless the
|
|
362
|
+
* operator explicitly sets `COLDPIN_TRUST_WORKSPACE_POLICY=1`.
|
|
363
|
+
*/
|
|
364
|
+
export function loadMcpPolicy(options
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
{
|
|
374
|
+
const baseCandidates = [];
|
|
375
|
+
if (options.explicitPolicyPath) {
|
|
376
|
+
baseCandidates.push(resolve(options.explicitPolicyPath));
|
|
377
|
+
} else {
|
|
378
|
+
baseCandidates.push(join(homedir(), ".coldpin.policy.json"));
|
|
379
|
+
baseCandidates.push(join(homedir(), ".npx-guard.policy.json"));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
let loadedPath = null;
|
|
383
|
+
let basePolicy = { ...DEFAULT_POLICY };
|
|
384
|
+
for (const p of baseCandidates) {
|
|
385
|
+
if (existsSync(p)) {
|
|
386
|
+
const raw = readPolicyJsonFile(p);
|
|
387
|
+
basePolicy = parseRawPolicyObject(raw, DEFAULT_POLICY);
|
|
388
|
+
loadedPath = p;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
let effectivePolicy = applyPrivateRegistryEnvOverlay(
|
|
394
|
+
basePolicy,
|
|
395
|
+
Boolean(options.explicitPolicyPath && loadedPath),
|
|
396
|
+
);
|
|
397
|
+
if (options.workspaceRoot) {
|
|
398
|
+
const wsCandidates = [
|
|
399
|
+
join(resolve(options.workspaceRoot), ".coldpin.policy.json"),
|
|
400
|
+
join(resolve(options.workspaceRoot), ".npx-guard.policy.json"),
|
|
401
|
+
];
|
|
402
|
+
for (const wp of wsCandidates) {
|
|
403
|
+
if (existsSync(wp)) {
|
|
404
|
+
try {
|
|
405
|
+
const wsRaw = readPolicyJsonFile(wp);
|
|
406
|
+
const wsParsed = parseRawPolicyObject(wsRaw, effectivePolicy);
|
|
407
|
+
effectivePolicy = options.trustWorkspacePolicy
|
|
408
|
+
? wsParsed
|
|
409
|
+
: mergePolicyAdditiveTighteningOnly(effectivePolicy, wsParsed);
|
|
410
|
+
if (!loadedPath && options.trustWorkspacePolicy) loadedPath = wp;
|
|
411
|
+
} catch {
|
|
412
|
+
// Malformed workspace policy cannot crash or downgrade the operator policy
|
|
413
|
+
}
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (options.forceOffline) {
|
|
420
|
+
effectivePolicy = { ...effectivePolicy, offline_mode: true };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const policy_sha256 = createHash("sha256").update(JSON.stringify(effectivePolicy)).digest("hex");
|
|
424
|
+
return { policy: effectivePolicy, policy_path: loadedPath, policy_sha256 };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
export function loadNpmrc(cwd , options = {}) {
|
|
435
|
+
const result = {
|
|
436
|
+
paths_loaded: [],
|
|
437
|
+
scoped_registries: {},
|
|
438
|
+
auth_token_env_by_host: {},
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const entries = [];
|
|
442
|
+
const homeRc = join(homedir(), ".npmrc");
|
|
443
|
+
if (existsSync(homeRc)) entries.push({ path: homeRc, allowAuthTokens: true });
|
|
444
|
+
|
|
445
|
+
if (options.pinnedNpmrcPath) {
|
|
446
|
+
const pinned = resolve(options.pinnedNpmrcPath);
|
|
447
|
+
if (existsSync(pinned) && pinned !== homeRc) {
|
|
448
|
+
entries.push({ path: pinned, allowAuthTokens: true });
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const includeWs = options.includeWorkspaceRegistries ?? true;
|
|
453
|
+
if (includeWs) {
|
|
454
|
+
const gitRoot = findGitRoot(cwd);
|
|
455
|
+
if (gitRoot && gitRoot !== resolve(cwd)) {
|
|
456
|
+
const rootRc = join(gitRoot, ".npmrc");
|
|
457
|
+
if (existsSync(rootRc) && rootRc !== homeRc) {
|
|
458
|
+
entries.push({ path: rootRc, allowAuthTokens: false });
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const cwdRc = join(resolve(cwd), ".npmrc");
|
|
462
|
+
if (existsSync(cwdRc) && cwdRc !== homeRc) {
|
|
463
|
+
entries.push({ path: cwdRc, allowAuthTokens: false });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
for (const { path: rcPath, allowAuthTokens } of entries) {
|
|
468
|
+
let content ;
|
|
469
|
+
try {
|
|
470
|
+
content = readCappedRegularFileSync(rcPath, MAX_NPMRC_BYTES).toString("utf8");
|
|
471
|
+
} catch {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
result.paths_loaded.push(rcPath);
|
|
475
|
+
const lines = content.split(/\r?\n/);
|
|
476
|
+
for (const rawLine of lines) {
|
|
477
|
+
const line = rawLine.trim();
|
|
478
|
+
if (!line || line.startsWith("#") || line.startsWith(";")) continue;
|
|
479
|
+
const eqIdx = line.indexOf("=");
|
|
480
|
+
if (eqIdx <= 0) continue;
|
|
481
|
+
const key = line.slice(0, eqIdx).trim();
|
|
482
|
+
const val = line.slice(eqIdx + 1).trim();
|
|
483
|
+
|
|
484
|
+
if (key === "registry") {
|
|
485
|
+
result.default_registry = val.replace(/\/+$/, "");
|
|
486
|
+
} else if (key.startsWith("@") && key.endsWith(":registry")) {
|
|
487
|
+
const scope = key.slice(0, -":registry".length).toLowerCase();
|
|
488
|
+
result.scoped_registries[scope] = val.replace(/\/+$/, "");
|
|
489
|
+
} else if (allowAuthTokens && key.startsWith("//") && key.endsWith(":_authToken")) {
|
|
490
|
+
// Security [MCP-09]: parse `:_authToken` ONLY from $HOME/.npmrc or operator-pinned config
|
|
491
|
+
const hostPath = key.slice(2, -":_authToken".length).replace(/^\/+|\/+$/g, "");
|
|
492
|
+
const envMatch = /^\$\{([A-Z0-9_]+)\}$/.exec(val);
|
|
493
|
+
if (hostPath && envMatch?.[1]) {
|
|
494
|
+
result.auth_token_env_by_host[hostPath] = envMatch[1];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (process.env["npm_config_registry"]) {
|
|
501
|
+
result.default_registry = process.env["npm_config_registry"].replace(/\/+$/, "");
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function normalizeHostPathKey(rawKey ) {
|
|
508
|
+
const trimmed = rawKey.replace(/^\/+|\/+$/g, "");
|
|
509
|
+
const slashIdx = trimmed.indexOf("/");
|
|
510
|
+
if (slashIdx === -1) return trimmed.toLowerCase();
|
|
511
|
+
return `${trimmed.slice(0, slashIdx).toLowerCase()}${trimmed.slice(slashIdx)}`;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
export function resolveAuthTokenForUrl(
|
|
515
|
+
registryUrl ,
|
|
516
|
+
npmrc ,
|
|
517
|
+
env = process.env,
|
|
518
|
+
) {
|
|
519
|
+
try {
|
|
520
|
+
const parsed = new URL(registryUrl);
|
|
521
|
+
// Security [MCP-09]: never resolve Bearer credentials for non-HTTPS URLs or public npm registries
|
|
522
|
+
if (parsed.protocol !== "https:") return undefined;
|
|
523
|
+
if (PUBLIC_NPM_HOSTS.has(parsed.hostname.toLowerCase())) return undefined;
|
|
524
|
+
const hostLower = parsed.host.toLowerCase();
|
|
525
|
+
const pathClean = parsed.pathname.replace(/\/+$/, "");
|
|
526
|
+
const hostAndPath = pathClean ? `${hostLower}${pathClean}` : hostLower;
|
|
527
|
+
for (const [k, envVar] of Object.entries(npmrc.auth_token_env_by_host)) {
|
|
528
|
+
const kNorm = normalizeHostPathKey(k);
|
|
529
|
+
if (!kNorm) continue;
|
|
530
|
+
// Security [MCP-09]: exact host or '/'-segment boundary match (prevents corp.local.evil.com matching corp.local)
|
|
531
|
+
if (hostAndPath === kNorm || hostAndPath.startsWith(`${kNorm}/`)) {
|
|
532
|
+
return sanitizeOperatorEnvValue(env[envVar]);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
// Optional enterprise Antigravity variables overlay (`[PLG-09]`): exact HTTPS host+path match only
|
|
536
|
+
const envRegUrl = sanitizeOperatorEnvValue(env["COLDPIN_PRIVATE_REGISTRY_URL"]);
|
|
537
|
+
const envToken = sanitizeOperatorEnvValue(env["COLDPIN_REGISTRY_TOKEN"]);
|
|
538
|
+
if (envRegUrl && envToken && isValidPrivateRegistryEnvUrl(envRegUrl)) {
|
|
539
|
+
const envParsed = new URL(envRegUrl);
|
|
540
|
+
const envHostPath = `${envParsed.host.toLowerCase()}${envParsed.pathname.replace(/\/+$/, "")}`;
|
|
541
|
+
if (hostAndPath === envHostPath || hostAndPath.startsWith(`${envHostPath}/`)) {
|
|
542
|
+
return envToken;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
} catch {
|
|
546
|
+
return undefined;
|
|
547
|
+
}
|
|
548
|
+
return undefined;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Private-scope-first router with fuzzy Levenshtein typo guard.
|
|
553
|
+
* Guarantees private scopes and private prefixes NEVER leak to public registry.npmjs.org.
|
|
554
|
+
*/
|
|
555
|
+
export function routeRegistry(
|
|
556
|
+
packageOrScope ,
|
|
557
|
+
policy ,
|
|
558
|
+
npmrc ,
|
|
559
|
+
) {
|
|
560
|
+
const normalized = packageOrScope.trim().toLowerCase();
|
|
561
|
+
const scopeMatch = /^(@[^/\s]+)/.exec(normalized);
|
|
562
|
+
const scope = scopeMatch?.[1];
|
|
563
|
+
|
|
564
|
+
const allPrivateScopes = new Set ([
|
|
565
|
+
...policy.private_scopes,
|
|
566
|
+
...Object.keys(policy.private_registries).map((s) => s.toLowerCase()),
|
|
567
|
+
...Object.keys(npmrc.scoped_registries).filter(
|
|
568
|
+
(s) => !isPublicNpmRegistryUrl(npmrc.scoped_registries[s] ?? ""),
|
|
569
|
+
),
|
|
570
|
+
]);
|
|
571
|
+
|
|
572
|
+
if (scope) {
|
|
573
|
+
const policyReg = policy.private_registries[scope];
|
|
574
|
+
const npmrcReg = npmrc.scoped_registries[scope];
|
|
575
|
+
const resolvedPrivate = policyReg ?? npmrcReg;
|
|
576
|
+
if (resolvedPrivate && !isPublicNpmRegistryUrl(resolvedPrivate)) {
|
|
577
|
+
return {
|
|
578
|
+
route: "private",
|
|
579
|
+
registry_url: resolvedPrivate.replace(/\/+$/, ""),
|
|
580
|
+
auth_token: resolveAuthTokenForUrl(resolvedPrivate, npmrc),
|
|
581
|
+
matched_scope_or_prefix: scope,
|
|
582
|
+
reason: `Scoped package ${scope} routed to private registry.`,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (allPrivateScopes.has(scope)) {
|
|
587
|
+
return {
|
|
588
|
+
route: "blocked_unconfigured",
|
|
589
|
+
registry_url: "",
|
|
590
|
+
matched_scope_or_prefix: scope,
|
|
591
|
+
reason: `Private scope ${scope} declared in policy without a configured private registry URL; public npm lookup blocked.`,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// Fuzzy typo guard: block near-misses & single transpositions of configured private scopes (e.g., @amce vs @acme)
|
|
596
|
+
for (const priv of allPrivateScopes) {
|
|
597
|
+
const a = scope.slice(1);
|
|
598
|
+
const b = priv.slice(1);
|
|
599
|
+
const isTransposition =
|
|
600
|
+
a.length === b.length &&
|
|
601
|
+
a.length >= 4 &&
|
|
602
|
+
(() => {
|
|
603
|
+
const diffs = [];
|
|
604
|
+
for (let i = 0; i < a.length; i++) {
|
|
605
|
+
if (a[i] !== b[i]) diffs.push(i);
|
|
606
|
+
if (diffs.length > 2) return false;
|
|
607
|
+
}
|
|
608
|
+
return diffs.length === 2 && diffs[1] === diffs[0] + 1 && a[diffs[0] ] === b[diffs[1] ] && a[diffs[1] ] === b[diffs[0] ];
|
|
609
|
+
})();
|
|
610
|
+
if (a.length >= 4 && b.length >= 4 && (levenshtein(a, b) <= 1 || isTransposition)) {
|
|
611
|
+
return {
|
|
612
|
+
route: "blocked_typo",
|
|
613
|
+
registry_url: "",
|
|
614
|
+
matched_scope_or_prefix: priv,
|
|
615
|
+
reason: `Scope ${scope} is 1 edit/transposition away from private scope ${priv}; blocked to prevent internal namespace leak.`,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Unscoped private prefix check
|
|
622
|
+
const bareName = scope ? normalized.slice(scope.length + 1) : normalized;
|
|
623
|
+
for (const prefix of policy.private_prefixes) {
|
|
624
|
+
if (bareName.startsWith(prefix)) {
|
|
625
|
+
const defaultPriv =
|
|
626
|
+
npmrc.default_registry && !isPublicNpmRegistryUrl(npmrc.default_registry)
|
|
627
|
+
? npmrc.default_registry
|
|
628
|
+
: !isPublicNpmRegistryUrl(policy.default_registry)
|
|
629
|
+
? policy.default_registry
|
|
630
|
+
: "";
|
|
631
|
+
if (defaultPriv) {
|
|
632
|
+
return {
|
|
633
|
+
route: "private",
|
|
634
|
+
registry_url: defaultPriv,
|
|
635
|
+
auth_token: resolveAuthTokenForUrl(defaultPriv, npmrc),
|
|
636
|
+
matched_scope_or_prefix: prefix,
|
|
637
|
+
reason: `Unscoped package matching private prefix '${prefix}' routed to private registry.`,
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
return {
|
|
641
|
+
route: "blocked_unconfigured",
|
|
642
|
+
registry_url: "",
|
|
643
|
+
matched_scope_or_prefix: prefix,
|
|
644
|
+
reason: `Package matches private prefix '${prefix}' but no private registry is configured; public npm lookup blocked.`,
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const targetRegistry = (npmrc.default_registry ?? policy.default_registry).replace(/\/+$/, "");
|
|
650
|
+
const isPrivate = !isPublicNpmRegistryUrl(targetRegistry);
|
|
651
|
+
return {
|
|
652
|
+
route: isPrivate ? "private" : "public",
|
|
653
|
+
registry_url: targetRegistry,
|
|
654
|
+
auth_token: isPrivate ? resolveAuthTokenForUrl(targetRegistry, npmrc) : undefined,
|
|
655
|
+
reason: isPrivate ? "Routed via configured default private registry." : "Routed to public npm registry.",
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function extractDiscoveryTokens(rawValue ) {
|
|
660
|
+
const out = [];
|
|
661
|
+
for (const rawTok of rawValue.split(/\s+/).filter(Boolean)) {
|
|
662
|
+
const cleaned = rawTok.replace(/^["'`(,]+|["'`),.;:]+$/g, "");
|
|
663
|
+
if (!cleaned) continue;
|
|
664
|
+
out.push(cleaned);
|
|
665
|
+
// Unwrap npm search qualifiers such as `scope:acme`, `maintainer:acme-internal-bot`, `keywords:@acme/foo`
|
|
666
|
+
const qualMatch = /^(?:scope|maintainer|author|keywords|not):(.+)$/i.exec(cleaned);
|
|
667
|
+
if (qualMatch?.[1]) {
|
|
668
|
+
const inner = qualMatch[1].trim();
|
|
669
|
+
out.push(inner);
|
|
670
|
+
if (cleaned.toLowerCase().startsWith("scope:") && !inner.startsWith("@")) {
|
|
671
|
+
out.push(`@${inner}`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
return out;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Inspects every whitespace-separated token across `query`, `org`, `creator`, and `category`
|
|
680
|
+
* so internal scopes, private prefixes, `scope:` qualifiers, or secret-shaped strings cannot
|
|
681
|
+
* leak to public `registry.npmjs.org` (`[MCP-04]`).
|
|
682
|
+
*/
|
|
683
|
+
export function routeDiscoveryQuery(
|
|
684
|
+
query ,
|
|
685
|
+
org ,
|
|
686
|
+
policy ,
|
|
687
|
+
npmrc ,
|
|
688
|
+
extra ,
|
|
689
|
+
) {
|
|
690
|
+
const allRawFields = [query, org ?? "", extra?.creator ?? "", extra?.category ?? ""];
|
|
691
|
+
for (const field of allRawFields) {
|
|
692
|
+
if (hasSecretLikeDiscoveryToken(field)) {
|
|
693
|
+
return {
|
|
694
|
+
route: "blocked_secret",
|
|
695
|
+
registry_url: "",
|
|
696
|
+
reason: "Blocked discovery query containing credential-shaped or secret-like material.",
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const tokens = [];
|
|
702
|
+
if (org?.trim()) {
|
|
703
|
+
const trimmedOrg = org.trim();
|
|
704
|
+
tokens.push(trimmedOrg.startsWith("@") ? trimmedOrg : `@${trimmedOrg}`);
|
|
705
|
+
tokens.push(...extractDiscoveryTokens(trimmedOrg));
|
|
706
|
+
}
|
|
707
|
+
tokens.push(...extractDiscoveryTokens(query));
|
|
708
|
+
if (extra?.creator?.trim()) {
|
|
709
|
+
const c = extra.creator.trim();
|
|
710
|
+
tokens.push(...extractDiscoveryTokens(c));
|
|
711
|
+
if (!c.startsWith("@")) tokens.push(`@${c}`);
|
|
712
|
+
}
|
|
713
|
+
if (extra?.category?.trim()) {
|
|
714
|
+
tokens.push(...extractDiscoveryTokens(extra.category.trim()));
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
let privateMatch = null;
|
|
718
|
+
for (const tok of tokens) {
|
|
719
|
+
if (!tok) continue;
|
|
720
|
+
const r = routeRegistry(tok, policy, npmrc);
|
|
721
|
+
if (r.route === "blocked_typo" || r.route === "blocked_unconfigured") {
|
|
722
|
+
return r;
|
|
723
|
+
}
|
|
724
|
+
if (r.route === "private" && !privateMatch) {
|
|
725
|
+
privateMatch = r;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return privateMatch ?? routeRegistry(tokens[0] ?? "", policy, npmrc);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
export async function probeHostCapabilitiesAsync() {
|
|
732
|
+
let gitAvailable = false;
|
|
733
|
+
let gitPartialCloneSupported = false;
|
|
734
|
+
let reaCliAvailable = false;
|
|
735
|
+
let reaCliCommand ;
|
|
736
|
+
|
|
737
|
+
try {
|
|
738
|
+
const { stdout } = await execFileAsync("git", ["--version"], {
|
|
739
|
+
encoding: "utf8",
|
|
740
|
+
timeout: 3000,
|
|
741
|
+
windowsHide: true,
|
|
742
|
+
});
|
|
743
|
+
gitAvailable = stdout.toLowerCase().includes("git version");
|
|
744
|
+
const verMatch = /(\d+)\.(\d+)/.exec(stdout);
|
|
745
|
+
if (verMatch?.[1] && verMatch[2]) {
|
|
746
|
+
const maj = Number(verMatch[1]);
|
|
747
|
+
const min = Number(verMatch[2]);
|
|
748
|
+
gitPartialCloneSupported = maj > 2 || (maj === 2 && min >= 25);
|
|
749
|
+
}
|
|
750
|
+
} catch {
|
|
751
|
+
gitAvailable = false;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
for (const candidate of ["rea", "rea-agents"]) {
|
|
755
|
+
try {
|
|
756
|
+
await execFileAsync(candidate, ["--version"], {
|
|
757
|
+
encoding: "utf8",
|
|
758
|
+
timeout: 2000,
|
|
759
|
+
windowsHide: true,
|
|
760
|
+
});
|
|
761
|
+
reaCliAvailable = true;
|
|
762
|
+
reaCliCommand = candidate;
|
|
763
|
+
break;
|
|
764
|
+
} catch {
|
|
765
|
+
// Not installed on PATH; never auto-bootstrap via npx -y
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return {
|
|
770
|
+
node_version: process.version,
|
|
771
|
+
git_available: gitAvailable,
|
|
772
|
+
git_partial_clone_supported: gitPartialCloneSupported,
|
|
773
|
+
rea_cli_available: reaCliAvailable,
|
|
774
|
+
...(reaCliCommand ? { rea_cli_command: reaCliCommand } : {}),
|
|
775
|
+
sqlite_available: true,
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
//# sourceURL=config/policy.ts
|