Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(mcp): open a sign-in page on this machine (http://127.0.0.1) instead of cancelling it (#4013)
Rishabh Balabomma7918c401ebf8
diff --git a/src/lib/mcp-sign-in.test.ts b/src/lib/mcp-sign-in.test.tsindex 442a455d98..d145394031 100644--- a/src/lib/mcp-sign-in.test.ts+++ b/src/lib/mcp-sign-in.test.ts@@ -26,6 +26,15 @@ describe("mcpSignInLink", () => {expect(mcpSignInLink("https://user:[email protected]/")).toBeNull();expect(mcpSignInLink(null)).toBeNull();});++ it("accepts a plain http sign-in page only on this machine (#3994)", () => {+ expect(mcpSignInLink("http://127.0.0.1:3773/oauth/mcp/authorize?x=1")).toBe("http://127.0.0.1:3773/oauth/mcp/authorize?x=1");+ expect(mcpSignInLink("http://localhost:3773/authorize")).toBe("http://localhost:3773/authorize");+ expect(mcpSignInLink("http://[::1]:3773/authorize")).toBe("http://[::1]:3773/authorize");+ expect(mcpSignInLink("http://127.0.0.1.evil.example/authorize")).toBeNull();+ expect(mcpSignInLink("http://192.168.1.5/authorize")).toBeNull();+ expect(mcpSignInLink("http://user:[email protected]/authorize")).toBeNull();+ });});describe("runMcpSignIn", () => {@@ -55,6 +64,21 @@ describe("runMcpSignIn", () => {expect(calls).toContainEqual(["DELETE", `/api/mcp/servers/hf/sign-in/${waiting.flowId}`]);});+ it("opens a local http sign-in page instead of cancelling the flow (#3994)", async () => {+ const local = { ...waiting, authorizationUrl: "http://127.0.0.1:3773/oauth/mcp/authorize?client_id=x" };+ const calls: Array<[string, string]> = [];+ const statuses = [{ ...local }, { ...local, phase: "succeeded", authorizationUrl: null }];+ const api = vi.fn(async (path: string, init?: { method?: string }) => {+ calls.push([init?.method ?? "GET", path]);+ return init?.method === "POST" ? { auth: local } : { auth: statuses.shift() };+ });+ const open = vi.fn(async () => {});+ const result = await runMcpSignIn("t3", { api, open, sleep: async () => {} });+ expect(open).toHaveBeenCalledWith(local.authorizationUrl);+ expect(result.phase).toBe("succeeded");+ expect(calls.some(([method]) => method === "DELETE")).toBe(false);+ });+it("cancels on the server when the person cancels", async () => {const { api, calls } = stubApi([{ ...waiting }, { ...waiting }]);const controller = new AbortController();diff --git a/src/lib/mcp-sign-in.ts b/src/lib/mcp-sign-in.tsindex c40f8f0fa8..5d52d1f8ce 100644--- a/src/lib/mcp-sign-in.ts+++ b/src/lib/mcp-sign-in.ts@@ -19,12 +19,17 @@ interface Deps {const POLL_MS = 1_500;-/** Only an https page may be opened as a sign-in link. */+// Same rule as the server's isAllowedAuthUrl: a sign-in page on this machine may be plain http.+const LOOPBACK_HOSTS = new Set(["127.0.0.1", "localhost", "[::1]"]);++/** Only an https page, or an http page on a loopback host, may be opened as a sign-in link. */export function mcpSignInLink(value: string | null | undefined): string | null {if (!value) return null;try {const url = new URL(value);- return url.protocol === "https:" && !url.username && !url.password ? url.href : null;+ if (url.username || url.password) return null;+ if (url.protocol === "https:") return url.href;+ return url.protocol === "http:" && LOOPBACK_HOSTS.has(url.hostname) ? url.href : null;} catch {return null;}