Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(skills): decode GitHub branch refs before resolving imports
Afloatb47e8ef71f83
diff --git a/server/skill-fetch.test.ts b/server/skill-fetch.test.tsindex 5f214c3975..a631ccaef7 100644--- a/server/skill-fetch.test.ts+++ b/server/skill-fetch.test.ts@@ -25,6 +25,31 @@ const ok = <T,>(result: { skills: T[] } | { error: string }) => {};describe("importing a skill's whole folder", () => {+ it.each([+ "https://github.com/a/b/tree/feature%2Fpdf/skills/pdf",+ "https://github.com/a/b/blob/feature%2Fpdf/skills/pdf/SKILL.md",+ "https://raw.githubusercontent.com/a/b/feature%2Fpdf/skills/pdf/SKILL.md",+ "https://raw.githubusercontent.com/a/b/refs/heads/feature%2Fpdf/skills/pdf/SKILL.md",+ ])("decodes the branch segment once when importing %s", async (source) => {+ const github = fakeGitHub({ "a/b": PDF_SKILL });+ const expected = "https://api.github.com/repos/a/b/commits/feature%2Fpdf";+ const fetcher: typeof fetch = async (input, init) => {+ if (String(input).includes("/commits/") && String(input) !== expected) return new Response(null, { status: 404 });+ return github.fetch(input, init);+ };+ expect(parseSkillSource(source)).toMatchObject({ ref: "feature/pdf", path: "skills/pdf" });+ const [skill] = ok(await fetchSkillFromSource(source, fetcher));+ expect(skill!.github).toMatchObject({ ref: "feature/pdf", commit: github.commitOf("a/b") });+ expect(github.requests[0]).toBe(expected);+ const [updated] = ok(await fetchSkillFromSource(githubSkillLink(skill!.github!), fetcher));+ expect(updated!.github).toEqual(skill!.github);+ });++ it("preserves literal percent escapes in a branch and rejects malformed URL escapes", () => {+ expect(parseSkillSource("https://github.com/a/b/tree/feature%252Fpdf/skills/pdf")).toMatchObject({ ref: "feature%2Fpdf" });+ expect(parseSkillSource("https://github.com/a/b/tree/bad%ZZ/skills/pdf")).toHaveProperty("error");+ });+it("brings in every file below the folder at one commit, binaries and executable bits included", async () => {const github = fakeGitHub({ "a/b": PDF_SKILL });const [skill] = ok(await fetchSkillFromSource("https://github.com/a/b/tree/main/skills/pdf", github.fetch));diff --git a/server/skill-fetch.ts b/server/skill-fetch.tsindex 174c4f0e73..855127e3f8 100644--- a/server/skill-fetch.ts+++ b/server/skill-fetch.ts@@ -85,6 +85,8 @@ function decodedPath(path: string): string | null {}function target(owner: string, repo: string, ref: string | undefined, path: string, extra: Partial<Target> = {}): Target | { error: string } {+ try { ref = ref === undefined ? undefined : decodeURIComponent(ref); }+ catch { return { error: "that does not look like a GitHub or skills.sh repository, folder, or SKILL.md URL" }; }const decoded = decodedPath(path);if (!OWNER_OR_REPO.test(owner) || !OWNER_OR_REPO.test(repo) || [owner, repo].some((part) => /^\.+$/.test(part)) || decoded === null ||(ref !== undefined && (!ref || ref === "." || ref === ".." || /[\s?#]/.test(ref)))) {