Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Train nov8-b: #4614 keeps the configured-URL rule on the server's own origin, lets a private server name a private sign-in host, never loopback
milind-sonid78830ab4f69
diff --git a/server/mcp-oauth-discovery.test.ts b/server/mcp-oauth-discovery.test.tsindex 80f0c942bb..b734f8442a 100644--- a/server/mcp-oauth-discovery.test.ts+++ b/server/mcp-oauth-discovery.test.ts@@ -181,6 +181,18 @@ describe("isAllowedDiscoveryUrl", () => {expect(isAllowedDiscoveryUrl("https://auth.example.com/prm", "https://mcp.example.com")).toBe(true);expect(isAllowedDiscoveryUrl("https://user:[email protected]/prm", "https://mcp.example.com")).toBe(false);});++ it("keeps https on the server's own address, lets a private server name another private host, never loopback", () => {+ // Plain http on the remote server's own origin is refused, as for a configured URL.+ expect(isAllowedDiscoveryUrl("http://mcp.example.com/token", "http://mcp.example.com")).toBe(false);+ // A LAN or VPN server may use a sign-in server on another private host...+ expect(isAllowedDiscoveryUrl("https://10.0.0.6/token", "https://10.0.0.5")).toBe(true);+ // ...but never this machine, however it is written.+ expect(isAllowedDiscoveryUrl("https://127.0.0.1/x", "https://10.0.0.5")).toBe(false);+ expect(isAllowedDiscoveryUrl("https://0.0.0.0/x", "https://10.0.0.5")).toBe(false);+ expect(isAllowedDiscoveryUrl("https://[::ffff:127.0.0.1]/x", "https://10.0.0.5")).toBe(false);+ expect(isAllowedDiscoveryUrl("https://[::]/x", "https://10.0.0.5")).toBe(false);+ });});describe("isAllowedAuthUrl", () => {diff --git a/server/mcp-oauth-discovery.ts b/server/mcp-oauth-discovery.tsindex 072dc1ecf0..2b86459eaf 100644--- a/server/mcp-oauth-discovery.ts+++ b/server/mcp-oauth-discovery.ts@@ -57,7 +57,8 @@ export function isAllowedDiscoveryUrl(value: string, trustedOrigin: string): boo}if (url.username || url.password) return false;if (url.protocol !== "https:" && url.protocol !== "http:") return false;- if (url.origin === trustedOrigin) return true;+ // The owner's own server keeps the configured-URL rule: https, or http on loopback only.+ if (url.origin === trustedOrigin) return isAllowedAuthUrl(value);let trusted: URL;try {trusted = new URL(trustedOrigin);@@ -66,8 +67,14 @@ export function isAllowedDiscoveryUrl(value: string, trustedOrigin: string): boo}// A local MCP server may name a sign-in server on another loopback port: both are code the owner installed here.if (isLoopbackName(trusted.hostname) && isLoopbackName(url.hostname)) return true;- if (url.protocol !== "https:") return false;- const host = url.hostname.replace(/^\[|\]$/gu, "").replace(/\.$/u, "").toLowerCase();+ if (url.protocol !== "https:" || isLoopbackName(url.hostname)) return false;+ // A server the owner reaches on a private network (LAN, VPN, tailnet) may name a sign-in server on another private host;+ // a public server may only name public ones.+ return isPublicHost(trusted.hostname) ? isPublicHost(url.hostname) : true;+}++function isPublicHost(hostname: string): boolean {+ const host = hostname.replace(/^\[|\]$/gu, "").replace(/\.$/u, "").toLowerCase();if (isIP(host)) return isPublicDomainAddress(host);return host.includes(".") && !LOCAL_SUFFIX.test(host);}@@ -75,8 +82,11 @@ export function isAllowedDiscoveryUrl(value: string, trustedOrigin: string): boofunction isLoopbackName(hostname: string): boolean {const host = hostname.replace(/^\[|\]$/gu, "").replace(/\.$/u, "").toLowerCase();if (host === "localhost") return true;- if (isIP(host) === 4) return host.startsWith("127.");- return isIP(host) === 6 && (host === "::1" || host === "0:0:0:0:0:0:0:1");+ if (isIP(host) === 4) return host.startsWith("127.") || host === "0.0.0.0";+ if (isIP(host) !== 6) return false;+ const mapped = /^::ffff:(.+)$/u.exec(host)?.[1];+ if (mapped) return mapped.startsWith("127.") || mapped === "0.0.0.0" || /^7f[0-9a-f]{2}:/u.test(mapped) || mapped === "0:0";+ return host === "::1" || host === "0:0:0:0:0:0:0:1" || host === "::" || host === "0:0:0:0:0:0:0:0";}export function resourceMetadataUrl(wwwAuthenticate: string | null): string | null {