Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(skills): discover skill names from pinned anonymous raw URLs

Ooi Pin Jun06c1215bedf4
diff --git a/server/skill-fetch.test.ts b/server/skill-fetch.test.ts
index 50627ab010..07b92e58fa 100644
--- a/server/skill-fetch.test.ts
+++ b/server/skill-fetch.test.ts
@@ -373,11 +373,40 @@ describe("skill fetch host pinning", () => {
if (!String(input).endsWith("/contents/skills/search-helper?ref=" + github.commitOf("a/b"))) return response;
return Response.json([{ type: "file", name: "SKILL.md", path: "skills/search-helper/SKILL.md", download_url }]);
}) as typeof fetch;
- expect(await fetchSkillFromSource("https://skills.sh/a/b/wanted-skill", fetcher))
- .toEqual({ error: expect.stringContaining('no skill named "wanted-skill"') });
+ const [skill] = ok(await fetchSkillFromSource("https://skills.sh/a/b/wanted-skill", fetcher));
+ expect(skill!.source).toBe("github.com/a/b/skills/search-helper");
expect(vi.mocked(fetcher).mock.calls.map(([input]) => String(input))).not.toContain(download_url);
});
+ it("does not fetch a Contents API download_url, even one with a temporary token", async () => {
+ const skillMd = "---\nname: Find Skills\ndescription: finds things\n---\n# A skill";
+ const github = fakeGitHub({ "vercel-labs/skills": { "skills/search-helper/SKILL.md": skillMd } });
+ const tokenized = `https://raw.githubusercontent.com/vercel-labs/skills/${github.commitOf("vercel-labs/skills")}/skills/search-helper/SKILL.md?token=v1.private-file-token`;
+ const fetcher = vi.fn(async (input: string | URL | Request, init?: RequestInit) => {
+ const response = await github.fetch(input, init);
+ if (!String(input).includes("/contents/skills/search-helper?ref=")) return response;
+ return Response.json([{
+ type: "file",
+ name: "SKILL.md",
+ path: "skills/search-helper/SKILL.md",
+ download_url: tokenized,
+ }]);
+ }) as typeof fetch;
+ const recorded = recordingFetch(fetcher);
+ const [skill] = ok(await fetchSkillFromSource(
+ "https://skills.sh/vercel-labs/skills/find-skills",
+ recorded.fetch,
+ undefined,
+ async () => SIGNED_IN,
+ ));
+ expect(skill!.source).toBe("github.com/vercel-labs/skills/skills/search-helper");
+ const urls = recorded.calls.map((call) => call.url);
+ expect(urls).not.toContain(tokenized);
+ expect(urls.every((url) => !url.includes("token="))).toBe(true);
+ expect(rawCalls(recorded.calls).every((call) => call.headers.get("authorization") === null && !call.url.includes("?"))).toBe(true);
+ expect(JSON.stringify(urls)).not.toContain("v1.private-file-token");
+ });
+
it("refuses a pasted plain-http raw link without fetching it", async () => {
const fetcher = vi.fn(async () => new Response("# A skill")) as typeof fetch;
expect(await fetchSkillFromSource("http://raw.githubusercontent.com/a/b/main/SKILL.md", fetcher))
diff --git a/server/skill-fetch.ts b/server/skill-fetch.ts
index 626fd85aa8..9434caf20c 100644
--- a/server/skill-fetch.ts
+++ b/server/skill-fetch.ts
@@ -265,11 +265,11 @@ const passThrough = (error: unknown) => error instanceof ImportLimitError || (er
const toSkillSlug = (name: string) =>
name.toLowerCase().replace(/[\s_]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
-async function skillNameFrom(entries: ContentEntry[], fetcher: typeof fetch): Promise<string | undefined> {
- const skillMd = entries.find((entry) => entry.type === "file" && entry.name === "SKILL.md" && entry.download_url);
+async function skillNameFrom(snapshot: Snapshot, entries: ContentEntry[], fetcher: typeof fetch): Promise<string | undefined> {
+ const skillMd = entries.find((entry) => entry.type === "file" && entry.name === "SKILL.md");
if (!skillMd) return undefined;
try {
- const text = (await fetchBytes(skillMd.download_url!, fetcher)).toString("utf8");
+ const text = (await fetchBytes(`https://${RAW_HOST}/${snapshot.owner}/${snapshot.repo}/${snapshot.commit}/${encodePath(skillMd.path)}`, fetcher)).toString("utf8");
return text.match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1]?.match(/^name:\s*(.+)$/m)?.[1]?.trim();
} catch (error) {
if (passThrough(error)) throw error;
@@ -285,7 +285,7 @@ async function discoverSkillDirs(target: Target, snapshot: Snapshot, fetcher: ty
const isWanted = async (dir: string, entries: ContentEntry[]) => {
if (!wanted) return true;
if (dirMatches(dir)) return true;
- const name = await skillNameFrom(entries, fetcher);
+ const name = await skillNameFrom(snapshot, entries, fetcher);
return !!name && toSkillSlug(name) === wanted;
};
if (root.some((entry) => entry.type === "file" && entry.name === "SKILL.md") && (await isWanted(target.path, root))) {