Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Image endpoints: refuse only the IPv6 metadata addresses, keep other unique-local hosts usable
milind-soni7fcaa4546ba7
diff --git a/shared/image-generation.test.ts b/shared/image-generation.test.tsindex c57424905e..6000122ef7 100644--- a/shared/image-generation.test.ts+++ b/shared/image-generation.test.ts@@ -8,6 +8,7 @@ describe("avatar image endpoint", () => {["http://[::1]:4000/v1", "http://[::1]:4000/v1"],["http://192.168.1.10:4000/v1", "http://192.168.1.10:4000/v1"],["http://host.docker.internal:4000/v1", "http://host.docker.internal:4000/v1"],+ ["http://[fd7a:115c:a1e0::1]:4000/v1", "http://[fd7a:115c:a1e0::1]:4000/v1"],])("normalizes an explicitly configured endpoint %s", (input, expected) => {expect(normalizeImageGenerationUrl(input)).toBe(expected);});@@ -15,7 +16,7 @@ describe("avatar image endpoint", () => {"file:///etc/passwd", "http://router.example/v1", "https://user:[email protected]/v1","https://router.example/v1?key=secret", "https://router.example/v1#secret","http://169.254.169.254/latest", "https://169.254.169.254/latest", "http://0.0.0.0/v1", "https://0.0.0.0/v1",- "http://[fd00:ec2::254]/latest", "https://[fd00:ec2::254]/latest", "http://[fc00::1]/v1", "https://[fdaa::3]/v1",+ "http://[fd00:ec2::254]/latest", "https://[fd00:ec2::254]/latest", "https://[fdaa::3]/v1","https://[::ffff:169.254.169.254]/latest", "https://[::]/v1", "https://[::ffff:0.0.0.0]/","https://100.100.100.200/latest", "https://[64:ff9b::a9fe:a9fe]/", "https://[2002:a9fe:a9fe::]/", "https://[fe80::1]/v1","not a URL",diff --git a/shared/image-generation.ts b/shared/image-generation.tsindex eca1d01f29..6cfe9e3c73 100644--- a/shared/image-generation.ts+++ b/shared/image-generation.ts@@ -124,7 +124,11 @@ function embeddedOctets(groups: number[]): number[] | null {return null;}-/** Cloud metadata, link-local, unique-local, and the unspecified address, including the IPv4 a translator would send.+/** The unique-local addresses that are cloud metadata services (AWS, Fly), as eight groups. */+const METADATA_IPV6 = ["fd00:ec2:0:0:0:0:0:254", "fdaa:0:0:0:0:0:0:3"];++/** Cloud metadata, link-local, and the unspecified address, including the IPv4 a translator would send. Other+ * unique-local addresses stay usable for a local router (Tailscale and home IPv6 are fd00::/8).* The settings page imports this file, so this stays free of node:net. */function refusedImageHost(host: string): boolean {const bare = bareHost(host);@@ -133,7 +137,7 @@ function refusedImageHost(host: string): boolean {const groups = ipv6Groups(bare);if (!groups) return false;const first = groups[0]!;- if (groups.every((part) => part === 0) || (first >= 0xfc00 && first <= 0xfdff) || (first >= 0xfe80 && first <= 0xfebf)) return true;+ if (groups.every((part) => part === 0) || METADATA_IPV6.includes(groups.map((part) => part.toString(16)).join(":")) || (first >= 0xfe80 && first <= 0xfebf)) return true;const embedded = embeddedOctets(groups);return embedded !== null && refusedImageHost(embedded.join("."));}@@ -153,7 +157,7 @@ export function normalizeImageGenerationUrl(value: string): string {const ipv4 = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(host);const local = host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local")|| host === "host.docker.internal" || host === "host.containers.internal"- || host === "[::1]"+ || host === "[::1]" || /^\[f[cd][0-9a-f]{2}:/.test(host)|| (ipv4 && (Number(ipv4[1]) === 127 || Number(ipv4[1]) === 10|| (Number(ipv4[1]) === 192 && Number(ipv4[2]) === 168)|| (Number(ipv4[1]) === 172 && Number(ipv4[2]) >= 16 && Number(ipv4[2]) <= 31)));