skillscout 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +128 -2
- package/dist/cli.js +181 -0
- package/dist/fetchSkill.js +111 -0
- package/dist/index.js +287 -0
- package/dist/install.js +269 -0
- package/dist/mcpConfig.js +79 -0
- package/dist/paths.js +19 -0
- package/dist/profile.js +193 -0
- package/dist/ref.js +59 -0
- package/dist/relevance.js +121 -0
- package/dist/sanitize.js +32 -0
- package/dist/scan/llm.js +147 -0
- package/dist/scan/rules.js +243 -0
- package/dist/search.js +179 -0
- package/dist/sources/github.js +111 -0
- package/dist/sources/http.js +47 -0
- package/dist/sources/mcpRegistry.js +26 -0
- package/dist/sources/osv.js +55 -0
- package/dist/sources/packages.js +180 -0
- package/dist/sources/remoteProbe.js +59 -0
- package/dist/sources/safeFetch.js +52 -0
- package/dist/sources/skillssh.js +50 -0
- package/dist/types.js +8 -0
- package/dist/updates.js +152 -0
- package/dist/verdict.js +147 -0
- package/dist/vetCache.js +22 -0
- package/dist/vetMcp.js +297 -0
- package/dist/vetPlugin.js +221 -0
- package/dist/vetSkill.js +75 -0
- package/package.json +54 -4
- package/skills/skillscout/SKILL.md +42 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getJson } from "./http.js";
|
|
2
|
+
import { sanitize } from "../sanitize.js";
|
|
3
|
+
export async function osvFindings(pkgs) {
|
|
4
|
+
if (pkgs.length === 0)
|
|
5
|
+
return { findings: [] };
|
|
6
|
+
let batch;
|
|
7
|
+
try {
|
|
8
|
+
batch = await getJson("https://api.osv.dev/v1/querybatch", {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: { "content-type": "application/json" },
|
|
11
|
+
body: JSON.stringify({ queries: pkgs.map((p) => ({ package: { name: p.name, ecosystem: p.ecosystem }, version: p.version })) }),
|
|
12
|
+
}, 20000);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
return { findings: [], error: `OSV lookup failed: ${e.message}` };
|
|
16
|
+
}
|
|
17
|
+
const findings = [];
|
|
18
|
+
const details = new Map();
|
|
19
|
+
const detail = (id) => {
|
|
20
|
+
if (!details.has(id))
|
|
21
|
+
details.set(id, getJson(`https://api.osv.dev/v1/vulns/${encodeURIComponent(id)}`, {}, 10000).catch(() => undefined));
|
|
22
|
+
return details.get(id);
|
|
23
|
+
};
|
|
24
|
+
await Promise.all(batch.results.map(async (r, i) => {
|
|
25
|
+
const p = pkgs[i];
|
|
26
|
+
const ids = (r.vulns ?? []).map((v) => v.id);
|
|
27
|
+
if (!ids.length)
|
|
28
|
+
return;
|
|
29
|
+
const mal = ids.filter((id) => id.startsWith("MAL-"));
|
|
30
|
+
if (mal.length) {
|
|
31
|
+
findings.push({
|
|
32
|
+
rule: "known-malicious-package",
|
|
33
|
+
severity: "critical",
|
|
34
|
+
file: p.via,
|
|
35
|
+
message: `${p.name}@${p.version} is listed as malicious (${mal.slice(0, 3).join(", ")})`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const vulns = ids.filter((id) => !id.startsWith("MAL-"));
|
|
39
|
+
if (!vulns.length)
|
|
40
|
+
return;
|
|
41
|
+
const ds = await Promise.all(vulns.slice(0, 5).map(detail));
|
|
42
|
+
const sevs = ds.map((d) => (d?.database_specific?.severity ?? "").toUpperCase());
|
|
43
|
+
const worst = ["CRITICAL", "HIGH", "MODERATE", "MEDIUM", "LOW"].find((s) => sevs.includes(s)) ?? "UNKNOWN";
|
|
44
|
+
// A known bug is not malice: it goes to review, never block on its own.
|
|
45
|
+
findings.push({
|
|
46
|
+
rule: "known-vulnerability",
|
|
47
|
+
severity: worst === "LOW" ? "low" : "medium",
|
|
48
|
+
file: p.via,
|
|
49
|
+
message: `${p.name}@${p.version} has ${vulns.length} known vulnerabilit${vulns.length === 1 ? "y" : "ies"} (worst: ${worst.toLowerCase()})`,
|
|
50
|
+
excerpt: sanitize(vulns.slice(0, 4).join(", "), 120),
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
return { findings };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=osv.js.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { gunzipSync, inflateRawSync } from "node:zlib";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import { getBytes, getJson } from "./http.js";
|
|
4
|
+
export async function npmVersion(pkg, version) {
|
|
5
|
+
const enc = pkg.startsWith("@") ? "@" + encodeURIComponent(pkg.slice(1)) : encodeURIComponent(pkg);
|
|
6
|
+
const doc = await getJson(`https://registry.npmjs.org/${enc}`);
|
|
7
|
+
const v = version ?? doc["dist-tags"].latest;
|
|
8
|
+
const info = v ? doc.versions[v] : undefined;
|
|
9
|
+
if (!info)
|
|
10
|
+
throw new Error(`npm package ${pkg}@${version ?? "latest"} not found`);
|
|
11
|
+
return { info, publishedAt: doc.time?.[info.version], latest: doc["dist-tags"].latest };
|
|
12
|
+
}
|
|
13
|
+
export async function npmWeeklyDownloads(pkg) {
|
|
14
|
+
try {
|
|
15
|
+
const d = await getJson(`https://api.npmjs.org/downloads/point/last-week/${pkg}`, {}, 5000);
|
|
16
|
+
return d.downloads;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Download an npm tarball and return its regular files (bounded). */
|
|
23
|
+
export async function npmTarballFiles(url, maxBytes = 8_000_000) {
|
|
24
|
+
const gz = await getBytes(url, {}, maxBytes, 30000);
|
|
25
|
+
return readTar(gunzipSync(gz, { maxOutputLength: 50_000_000 }));
|
|
26
|
+
}
|
|
27
|
+
/** Minimal ustar/pax reader. Only regular files are returned; links and devices are reported. */
|
|
28
|
+
export function readTar(buf, limits = { maxFiles: 2000, maxFileBytes: 1_000_000 },
|
|
29
|
+
/** Strip the archive's first path component (sdists use "<name>-<version>/"). */
|
|
30
|
+
stripFirst = false) {
|
|
31
|
+
const files = [];
|
|
32
|
+
const skipped = [];
|
|
33
|
+
let off = 0;
|
|
34
|
+
let paxPath;
|
|
35
|
+
while (off + 512 <= buf.length) {
|
|
36
|
+
const h = buf.subarray(off, off + 512);
|
|
37
|
+
if (h.every((b) => b === 0))
|
|
38
|
+
break;
|
|
39
|
+
const str = (s, l) => h.subarray(s, s + l).toString("utf8").replace(/\0.*$/s, "");
|
|
40
|
+
let name = str(0, 100);
|
|
41
|
+
const prefix = str(345, 155);
|
|
42
|
+
if (prefix)
|
|
43
|
+
name = `${prefix}/${name}`;
|
|
44
|
+
const size = parseInt(str(124, 12).trim() || "0", 8);
|
|
45
|
+
const mode = parseInt(str(100, 8).trim() || "0", 8);
|
|
46
|
+
const type = String.fromCharCode(h[156] || 48);
|
|
47
|
+
const dataStart = off + 512;
|
|
48
|
+
const data = buf.subarray(dataStart, dataStart + size);
|
|
49
|
+
off = dataStart + Math.ceil(size / 512) * 512;
|
|
50
|
+
if (type === "x") {
|
|
51
|
+
const m = data.toString("utf8").match(/\d+ path=([^\n]*)\n/);
|
|
52
|
+
paxPath = m?.[1];
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (type === "g")
|
|
56
|
+
continue;
|
|
57
|
+
let path = (paxPath ?? name).replace(/^\.\//, "");
|
|
58
|
+
path = stripFirst ? path.replace(/^[^/]+\//, "") : path.replace(/^package\//, "");
|
|
59
|
+
paxPath = undefined;
|
|
60
|
+
if (type === "5")
|
|
61
|
+
continue; // directory
|
|
62
|
+
if (type !== "0" && type !== "\0" && type !== "7") {
|
|
63
|
+
skipped.push({ path, reason: `non-regular tar entry (type ${type})` });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (path.split("/").includes("..") || path.startsWith("/")) {
|
|
67
|
+
skipped.push({ path, reason: "path traversal in archive" });
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (files.length >= limits.maxFiles) {
|
|
71
|
+
skipped.push({ path, reason: "file count limit" });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (size > limits.maxFileBytes) {
|
|
75
|
+
skipped.push({ path, reason: `file larger than ${limits.maxFileBytes} bytes` });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
files.push({ path, content: Buffer.from(data), executable: (mode & 0o111) !== 0 });
|
|
79
|
+
}
|
|
80
|
+
return { files, skipped };
|
|
81
|
+
}
|
|
82
|
+
export async function pypiVersion(pkg, version) {
|
|
83
|
+
const url = version
|
|
84
|
+
? `https://pypi.org/pypi/${encodeURIComponent(pkg)}/${encodeURIComponent(version)}/json`
|
|
85
|
+
: `https://pypi.org/pypi/${encodeURIComponent(pkg)}/json`;
|
|
86
|
+
const d = await getJson(url);
|
|
87
|
+
const sdist = d.urls.find((u) => u.packagetype === "sdist" && /\.tar\.gz$/.test(u.filename));
|
|
88
|
+
const wheel = d.urls.find((u) => u.packagetype === "bdist_wheel" && /-none-any\.whl$/.test(u.filename)) ?? d.urls.find((u) => u.packagetype === "bdist_wheel");
|
|
89
|
+
const pick = sdist ? { url: sdist.url, kind: "sdist", size: sdist.size } : wheel ? { url: wheel.url, kind: "wheel", size: wheel.size } : undefined;
|
|
90
|
+
return {
|
|
91
|
+
version: d.info.version,
|
|
92
|
+
dist: pick,
|
|
93
|
+
publishedAt: d.urls[0]?.upload_time_iso_8601,
|
|
94
|
+
homePage: d.info.home_page,
|
|
95
|
+
projectUrls: d.info.project_urls,
|
|
96
|
+
yanked: d.info.yanked,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Download and unpack a PyPI distribution in memory (sdist .tar.gz or wheel .zip). */
|
|
100
|
+
export async function pypiFiles(dist, maxBytes = 8_000_000) {
|
|
101
|
+
if (!dist.url.startsWith("https://files.pythonhosted.org/"))
|
|
102
|
+
throw new Error("Unexpected PyPI download host");
|
|
103
|
+
const buf = await getBytes(dist.url, {}, maxBytes, 30000);
|
|
104
|
+
return dist.kind === "sdist" ? readTar(gunzipSync(buf, { maxOutputLength: 50_000_000 }), undefined, true) : readZip(buf);
|
|
105
|
+
}
|
|
106
|
+
/** Minimal ZIP reader (stored + deflate). Encrypted, zip64 and traversal entries are skipped and reported. */
|
|
107
|
+
export function readZip(buf, limits = { maxFiles: 2000, maxFileBytes: 1_000_000 }) {
|
|
108
|
+
const files = [];
|
|
109
|
+
const skipped = [];
|
|
110
|
+
let eocd = -1;
|
|
111
|
+
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65_557); i--) {
|
|
112
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
113
|
+
eocd = i;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (eocd < 0)
|
|
118
|
+
throw new Error("Not a zip archive");
|
|
119
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
120
|
+
let off = buf.readUInt32LE(eocd + 16);
|
|
121
|
+
for (let n = 0; n < count && off + 46 <= buf.length; n++) {
|
|
122
|
+
if (buf.readUInt32LE(off) !== 0x02014b50)
|
|
123
|
+
break;
|
|
124
|
+
const flags = buf.readUInt16LE(off + 8);
|
|
125
|
+
const method = buf.readUInt16LE(off + 10);
|
|
126
|
+
const csize = buf.readUInt32LE(off + 20);
|
|
127
|
+
const usize = buf.readUInt32LE(off + 24);
|
|
128
|
+
const nameLen = buf.readUInt16LE(off + 28);
|
|
129
|
+
const extraLen = buf.readUInt16LE(off + 30);
|
|
130
|
+
const commentLen = buf.readUInt16LE(off + 32);
|
|
131
|
+
const extAttr = buf.readUInt32LE(off + 38);
|
|
132
|
+
const local = buf.readUInt32LE(off + 42);
|
|
133
|
+
const path = buf.subarray(off + 46, off + 46 + nameLen).toString("utf8");
|
|
134
|
+
off += 46 + nameLen + extraLen + commentLen;
|
|
135
|
+
if (path.endsWith("/"))
|
|
136
|
+
continue;
|
|
137
|
+
if (path.split("/").includes("..") || path.startsWith("/"))
|
|
138
|
+
skipped.push({ path, reason: "path traversal in archive" });
|
|
139
|
+
else if (flags & 1)
|
|
140
|
+
skipped.push({ path, reason: "encrypted entry" });
|
|
141
|
+
else if (csize === 0xffffffff || usize === 0xffffffff)
|
|
142
|
+
skipped.push({ path, reason: "zip64 entry not supported" });
|
|
143
|
+
else if (files.length >= limits.maxFiles)
|
|
144
|
+
skipped.push({ path, reason: "file count limit" });
|
|
145
|
+
else if (usize > limits.maxFileBytes)
|
|
146
|
+
skipped.push({ path, reason: `file larger than ${limits.maxFileBytes} bytes` });
|
|
147
|
+
else if (method !== 0 && method !== 8)
|
|
148
|
+
skipped.push({ path, reason: `unsupported compression ${method}` });
|
|
149
|
+
else {
|
|
150
|
+
const lname = buf.readUInt16LE(local + 26);
|
|
151
|
+
const lextra = buf.readUInt16LE(local + 28);
|
|
152
|
+
const start = local + 30 + lname + lextra;
|
|
153
|
+
const raw = buf.subarray(start, start + csize);
|
|
154
|
+
const content = method === 0 ? Buffer.from(raw) : inflateRawSync(raw, { maxOutputLength: limits.maxFileBytes + 1 });
|
|
155
|
+
files.push({ path, content, executable: ((extAttr >>> 16) & 0o111) !== 0 });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { files, skipped };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolve direct dependencies to the versions npm would pick today, using the
|
|
162
|
+
* abbreviated packument (which also says whether a version has install scripts).
|
|
163
|
+
* Transitive dependencies are not resolved.
|
|
164
|
+
*/
|
|
165
|
+
export async function resolveNpmDeps(deps, max = 60) {
|
|
166
|
+
const entries = Object.entries(deps).slice(0, max);
|
|
167
|
+
return Promise.all(entries.map(async ([name, range]) => {
|
|
168
|
+
try {
|
|
169
|
+
const enc = name.startsWith("@") ? "@" + encodeURIComponent(name.slice(1)) : encodeURIComponent(name);
|
|
170
|
+
const doc = await getJson(`https://registry.npmjs.org/${enc}`, { headers: { accept: "application/vnd.npm.install-v1+json" } }, 10000);
|
|
171
|
+
const latest = doc["dist-tags"].latest;
|
|
172
|
+
const version = latest && semver.satisfies(latest, range) ? latest : semver.maxSatisfying(Object.keys(doc.versions), range) ?? undefined;
|
|
173
|
+
return { name, range, version, hasInstallScript: version ? Boolean(doc.versions[version]?.hasInstallScript) : undefined };
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return { name, range };
|
|
177
|
+
}
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=packages.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
4
|
+
import { isPrivate, safeFetch } from "./safeFetch.js";
|
|
5
|
+
/**
|
|
6
|
+
* Connect to a remote MCP server and list its tools, without calling any.
|
|
7
|
+
* Tool descriptions are where "tool poisoning" lives, so this is the one
|
|
8
|
+
* thing worth inspecting on a server whose code we cannot see.
|
|
9
|
+
*/
|
|
10
|
+
export async function probeRemote(url, transport, timeoutMs = 15000) {
|
|
11
|
+
const target = checkTarget(url);
|
|
12
|
+
if (target)
|
|
13
|
+
return { status: "refused_target", reason: target };
|
|
14
|
+
const client = new Client({ name: "skillscout-probe", version: "0.1.0" });
|
|
15
|
+
const t = transport === "sse"
|
|
16
|
+
? new SSEClientTransport(new URL(url), { fetch: safeFetch })
|
|
17
|
+
: new StreamableHTTPClientTransport(new URL(url), { fetch: safeFetch });
|
|
18
|
+
const timer = new Promise((_, rej) => setTimeout(() => rej(new Error("timed out")), timeoutMs));
|
|
19
|
+
try {
|
|
20
|
+
await Promise.race([client.connect(t), timer]);
|
|
21
|
+
const res = await Promise.race([client.listTools(), timer]);
|
|
22
|
+
return {
|
|
23
|
+
status: "ok",
|
|
24
|
+
tools: res.tools.slice(0, 200).map((x) => ({
|
|
25
|
+
name: String(x.name),
|
|
26
|
+
description: String(x.description ?? ""),
|
|
27
|
+
inputSchema: x.inputSchema,
|
|
28
|
+
})),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
const msg = [e.message, e.cause?.message].filter(Boolean).join(": ");
|
|
33
|
+
if (/private address/i.test(msg))
|
|
34
|
+
return { status: "refused_target", reason: "Server resolves to a private/loopback address" };
|
|
35
|
+
if (/401|403|unauthori[sz]ed|forbidden|auth/i.test(msg))
|
|
36
|
+
return { status: "auth_required", reason: "Server requires authentication; tools could not be listed." };
|
|
37
|
+
return { status: "unreachable", reason: msg.slice(0, 200) };
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
await client.close().catch(() => { });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Cheap early rejection with a clear message; the real enforcement is safeFetch at connect time. */
|
|
44
|
+
function checkTarget(raw) {
|
|
45
|
+
let u;
|
|
46
|
+
try {
|
|
47
|
+
u = new URL(raw);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return "Invalid URL";
|
|
51
|
+
}
|
|
52
|
+
if (u.protocol !== "https:")
|
|
53
|
+
return "Only https remote servers are probed";
|
|
54
|
+
if (/^(localhost|.*\.local|.*\.internal)$/i.test(u.hostname))
|
|
55
|
+
return "Refusing to probe a local hostname";
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
export { isPrivate };
|
|
59
|
+
//# sourceMappingURL=remoteProbe.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { lookup as dnsLookup } from "node:dns";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
import { Agent, fetch as undiciFetch } from "undici";
|
|
4
|
+
/**
|
|
5
|
+
* A fetch that refuses to connect to private, loopback or link-local addresses.
|
|
6
|
+
* The check runs inside the socket's DNS lookup, i.e. at connect time for every
|
|
7
|
+
* connection (including redirects), so a hostname cannot pass a pre-check and
|
|
8
|
+
* then re-resolve to an internal address (DNS rebinding).
|
|
9
|
+
*/
|
|
10
|
+
export function isPrivate(ip) {
|
|
11
|
+
if (ip.includes(":")) {
|
|
12
|
+
const l = ip.toLowerCase();
|
|
13
|
+
if (l.startsWith("::ffff:"))
|
|
14
|
+
return isPrivate(l.slice(7));
|
|
15
|
+
return l === "::1" || l === "::" || l.startsWith("fc") || l.startsWith("fd") || l.startsWith("fe80");
|
|
16
|
+
}
|
|
17
|
+
const [a, b] = ip.split(".").map(Number);
|
|
18
|
+
return a === 10 || a === 127 || a === 0 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127) || a >= 224;
|
|
19
|
+
}
|
|
20
|
+
export function guardedLookup(hostname, options, cb) {
|
|
21
|
+
if (isIP(hostname)) {
|
|
22
|
+
if (isPrivate(hostname))
|
|
23
|
+
return cb(Object.assign(new Error(`Refusing to connect to private address ${hostname}`), { code: "EPRIVATE" }), "");
|
|
24
|
+
return cb(null, [{ address: hostname, family: isIP(hostname) }]);
|
|
25
|
+
}
|
|
26
|
+
dnsLookup(hostname, { ...options, all: true }, (err, addrs) => {
|
|
27
|
+
if (err)
|
|
28
|
+
return cb(err, "");
|
|
29
|
+
const list = addrs;
|
|
30
|
+
if (list.length === 0 || list.some((a) => isPrivate(a.address))) {
|
|
31
|
+
return cb(Object.assign(new Error(`Refusing to connect: ${hostname} resolves to a private address`), { code: "EPRIVATE" }), "");
|
|
32
|
+
}
|
|
33
|
+
// undici asks with all:true; answer in the form it asked for.
|
|
34
|
+
if (options.all)
|
|
35
|
+
cb(null, list);
|
|
36
|
+
else
|
|
37
|
+
cb(null, list[0].address, list[0].family);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const agent = new Agent({ connect: { lookup: guardedLookup } });
|
|
41
|
+
export const safeFetch = ((url, init) => {
|
|
42
|
+
const u = new URL(String(url));
|
|
43
|
+
if (u.protocol !== "https:")
|
|
44
|
+
return Promise.reject(new Error("Only https is allowed"));
|
|
45
|
+
// IP literals never go through DNS lookup, so check them here.
|
|
46
|
+
const host = u.hostname.replace(/^\[|\]$/g, "");
|
|
47
|
+
if (isIP(host) && isPrivate(host))
|
|
48
|
+
return Promise.reject(new Error(`Refusing to connect to private address ${host}`));
|
|
49
|
+
// Redirects could point at an IP literal and skip the check above, so they are not followed.
|
|
50
|
+
return undiciFetch(u, { ...init, redirect: "error", dispatcher: agent });
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=safeFetch.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getJson } from "./http.js";
|
|
2
|
+
import { sanitize } from "../sanitize.js";
|
|
3
|
+
const BASE = process.env.SKILLS_API_URL || "https://skills.sh";
|
|
4
|
+
export async function searchSkillsSh(query) {
|
|
5
|
+
const data = await getJson(`${BASE}/api/search?${new URLSearchParams({ q: query })}`);
|
|
6
|
+
return (data.skills ?? [])
|
|
7
|
+
.filter((s) => typeof s.id === "string" && s.id.split("/").length === 3)
|
|
8
|
+
.map((s) => ({
|
|
9
|
+
id: sanitize(s.id, 200),
|
|
10
|
+
source: sanitize(s.source, 200),
|
|
11
|
+
skill: sanitize(s.skillId ?? s.id.split("/")[2], 100),
|
|
12
|
+
name: sanitize(s.name, 100),
|
|
13
|
+
installs: Number(s.installs) || 0,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
/** Compact partner risk per skill, batched by source repo. */
|
|
17
|
+
export async function partnerRiskSummary(source, skills) {
|
|
18
|
+
if (skills.length === 0)
|
|
19
|
+
return {};
|
|
20
|
+
try {
|
|
21
|
+
const data = await getJson(`https://www.skills.sh/tele/audit?${new URLSearchParams({ source, skills: skills.join(",") })}`, {}, 5000);
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const [skill, providers] of Object.entries(data ?? {})) {
|
|
24
|
+
out[skill] = {};
|
|
25
|
+
for (const [p, v] of Object.entries(providers ?? {}))
|
|
26
|
+
out[skill][sanitize(p, 20)] = sanitize(v?.risk ?? "unknown", 20);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Detailed partner audits (Gen Agent Trust Hub, Socket, Snyk) for one skill. */
|
|
35
|
+
export async function partnerAudits(source, skill) {
|
|
36
|
+
try {
|
|
37
|
+
const data = await getJson(`${BASE}/api/v1/skills/audit/${encodeURIComponent(source)}/${encodeURIComponent(skill)}`, {}, 5000);
|
|
38
|
+
return (data.audits ?? []).map((a) => ({
|
|
39
|
+
provider: sanitize(a.provider, 60),
|
|
40
|
+
status: sanitize(a.status, 20),
|
|
41
|
+
risk: a.riskLevel ? sanitize(a.riskLevel, 20) : undefined,
|
|
42
|
+
summary: sanitize(a.summary, 300),
|
|
43
|
+
auditedAt: sanitize(a.auditedAt, 40),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=skillssh.js.map
|
package/dist/types.js
ADDED
package/dist/updates.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { hashInstalledDir, readLock } from "./install.js";
|
|
3
|
+
import { skillsDir } from "./paths.js";
|
|
4
|
+
import { getMcpServer } from "./sources/mcpRegistry.js";
|
|
5
|
+
import { resolveCommit } from "./sources/github.js";
|
|
6
|
+
import { vetMcp } from "./vetMcp.js";
|
|
7
|
+
import { vetSkill } from "./vetSkill.js";
|
|
8
|
+
import { fetchSkill } from "./fetchSkill.js";
|
|
9
|
+
import { vetPlugin } from "./vetPlugin.js";
|
|
10
|
+
/**
|
|
11
|
+
* Compare each locked entry with upstream. Updates are re-vetted but never
|
|
12
|
+
* applied automatically: a skill or server that was safe can turn hostile
|
|
13
|
+
* in a later version, so every upgrade goes through the same gate.
|
|
14
|
+
*/
|
|
15
|
+
export async function checkUpdates(projectDir, scope) {
|
|
16
|
+
const lock = await readLock(scope, projectDir);
|
|
17
|
+
const out = [];
|
|
18
|
+
for (const [key, e] of Object.entries(lock.entries)) {
|
|
19
|
+
try {
|
|
20
|
+
if (e.kind === "plugin") {
|
|
21
|
+
const [owner, repo] = e.source.split("/");
|
|
22
|
+
const head = await resolveCommit(owner, repo);
|
|
23
|
+
if (head === e.sha) {
|
|
24
|
+
out.push({ key, kind: "plugin", pinned: e.sha, latest: head, status: "up-to-date" });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const v = await vetPlugin({ owner, repo, skill: e.path.split("/").pop() || repo, path: e.path, ref: head });
|
|
28
|
+
out.push({
|
|
29
|
+
key,
|
|
30
|
+
kind: "plugin",
|
|
31
|
+
pinned: e.sha,
|
|
32
|
+
latest: head,
|
|
33
|
+
status: v.contentHash === e.contentHash ? "up-to-date" : "update-available",
|
|
34
|
+
...(v.contentHash === e.contentHash ? { detail: "Repo changed but this plugin's files did not." } : {
|
|
35
|
+
newVerdict: v.verdict,
|
|
36
|
+
newReasons: v.reasons,
|
|
37
|
+
detail: `To upgrade: install_plugin with ref "${e.source}:${e.path}" and sha "${head}".`,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (e.kind === "skill") {
|
|
43
|
+
const name = key.slice("skill:".length);
|
|
44
|
+
const dir = join(skillsDir(scope, projectDir), name);
|
|
45
|
+
const local = await hashInstalledDir(dir).catch(() => undefined);
|
|
46
|
+
if (!local) {
|
|
47
|
+
out.push({ key, kind: "skill", pinned: e.sha, status: "missing", detail: `${dir} not found` });
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (local !== e.contentHash) {
|
|
51
|
+
out.push({ key, kind: "skill", pinned: e.sha, status: "modified-locally", detail: "Installed files differ from what was vetted. Re-install or re-vet." });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const [owner, repo] = e.source.split("/");
|
|
55
|
+
const head = await resolveCommit(owner, repo);
|
|
56
|
+
if (head === e.sha) {
|
|
57
|
+
out.push({ key, kind: "skill", pinned: e.sha, latest: head, status: "up-to-date" });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
// Same id shape install_skill derives from "owner/repo:path", so the vet cache lines up.
|
|
61
|
+
const ref = { owner, repo, skill: e.path.split("/").pop() || repo, path: e.path, ref: head };
|
|
62
|
+
const { result } = await vetSkill(ref);
|
|
63
|
+
if (result.contentHash === e.contentHash) {
|
|
64
|
+
out.push({ key, kind: "skill", pinned: e.sha, latest: head, status: "up-to-date", detail: "Repo changed but this skill's files did not." });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const oldFiles = await localFileHashes(dir);
|
|
68
|
+
const fetched = await fetchSkill(ref);
|
|
69
|
+
const newFiles = new Map(fetched.files.map((f) => [f.path, f.content.toString("base64")]));
|
|
70
|
+
out.push({
|
|
71
|
+
key,
|
|
72
|
+
kind: "skill",
|
|
73
|
+
pinned: e.sha,
|
|
74
|
+
latest: head,
|
|
75
|
+
status: "update-available",
|
|
76
|
+
newVerdict: result.verdict,
|
|
77
|
+
newReasons: result.reasons,
|
|
78
|
+
changedFiles: diff(oldFiles, newFiles),
|
|
79
|
+
detail: `To upgrade: install_skill with ref "${e.source}:${e.path}" and sha "${head}".`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const isRemote = e.path.startsWith("remote:");
|
|
84
|
+
const entry = await getMcpServer(e.source);
|
|
85
|
+
const sameVersion = entry.version === (e.registryVersion ?? e.sha);
|
|
86
|
+
if (sameVersion && !isRemote) {
|
|
87
|
+
out.push({ key, kind: "mcp", pinned: e.sha, latest: e.sha, status: "up-to-date" });
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
// Remote servers can change their tools without a new version, so always re-probe them.
|
|
91
|
+
const v = await vetMcp(e.source, { version: entry.version, prefer: isRemote ? "remote" : "package" });
|
|
92
|
+
if (sameVersion && isRemote) {
|
|
93
|
+
if (v.files.length === 0) {
|
|
94
|
+
out.push({ key, kind: "mcp", pinned: e.sha, status: "unverified", detail: `Could not re-list tools: ${v.reasons.join(" ")}` });
|
|
95
|
+
}
|
|
96
|
+
else if (v.contentHash === e.contentHash) {
|
|
97
|
+
out.push({ key, kind: "mcp", pinned: e.sha, latest: e.sha, status: "up-to-date", detail: "Tool list and descriptions unchanged." });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
out.push({
|
|
101
|
+
key,
|
|
102
|
+
kind: "mcp",
|
|
103
|
+
pinned: e.sha,
|
|
104
|
+
latest: e.sha,
|
|
105
|
+
status: "changed-upstream",
|
|
106
|
+
newVerdict: v.verdict,
|
|
107
|
+
newReasons: v.reasons,
|
|
108
|
+
detail: "The remote server's tools or descriptions changed since install, with no version bump. Re-vetted; review before continuing to use it.",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
out.push({
|
|
114
|
+
key,
|
|
115
|
+
kind: "mcp",
|
|
116
|
+
pinned: e.sha,
|
|
117
|
+
latest: v.sha,
|
|
118
|
+
status: "update-available",
|
|
119
|
+
newVerdict: v.verdict,
|
|
120
|
+
newReasons: v.reasons,
|
|
121
|
+
detail: `To upgrade: install_mcp_server with name "${e.source}" and version "${v.sha}".`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
out.push({ key, kind: e.kind, pinned: e.sha, status: "error", detail: err.message });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
async function localFileHashes(dir) {
|
|
132
|
+
const { readdir, readFile } = await import("node:fs/promises");
|
|
133
|
+
const m = new Map();
|
|
134
|
+
async function walk(d, prefix) {
|
|
135
|
+
for (const e of await readdir(d, { withFileTypes: true })) {
|
|
136
|
+
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
137
|
+
if (e.isDirectory())
|
|
138
|
+
await walk(join(d, e.name), rel);
|
|
139
|
+
else if (e.isFile())
|
|
140
|
+
m.set(rel, (await readFile(join(d, e.name))).toString("base64"));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
await walk(dir, "");
|
|
144
|
+
return m;
|
|
145
|
+
}
|
|
146
|
+
function diff(a, b) {
|
|
147
|
+
const added = [...b.keys()].filter((k) => !a.has(k));
|
|
148
|
+
const removed = [...a.keys()].filter((k) => !b.has(k));
|
|
149
|
+
const changed = [...b.keys()].filter((k) => a.has(k) && a.get(k) !== b.get(k));
|
|
150
|
+
return { added, removed, changed };
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=updates.js.map
|