Skip to content

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

fix(browser): let the desktop browser through fake-IP proxies (198.18.0.0/15)

AdityaUmale86af78e4aec0
diff --git a/server/browser/egress/policy.test.ts b/server/browser/egress/policy.test.ts
index 432333d93c..848ebf4018 100644
--- a/server/browser/egress/policy.test.ts
+++ b/server/browser/egress/policy.test.ts
@@ -7,6 +7,8 @@ import { addressClass, allowList, browserEgressConfigSchema, namesThisMachine, p
const own = new BlockList();
own.addAddress("198.51.100.7", "ipv4");
own.addAddress("192.168.1.5", "ipv4");
+// The address a fake-IP proxy (Clash, Surge) gives its own TUN interface.
+own.addAddress("198.18.0.1", "ipv4");
const rules = (host: EgressHost, over: Partial<EgressRules> = {}): EgressRules => ({
host,
@@ -111,6 +113,19 @@ describe("what each host lets a bot's browser reach", () => {
expect(await decide("desktop", "nas.local:443", ["192.168.1.20"], { localNetwork: false })).toBe("local-network");
});
+ it("lets the desktop reach a proxy's fake-IP answers (198.18.0.0/15) like the local network; servers and Cloud keep refusing them", async () => {
+ // Clash, Surge and similar proxies in TUN + fake-IP mode answer every name with an address in 198.18.0.0/15.
+ expect(await decide("desktop", "example.com:443", ["198.18.0.7"])).toBeNull();
+ expect(await decide("desktop", "github.com:443", ["198.19.255.254", "::ffff:198.18.1.2"])).toBeNull();
+ expect(await decide("desktop", "example.com:443", ["198.18.0.7"], { localNetwork: false })).toBe("local-network");
+ // The proxy's own interface is this computer: only a name for this machine reaches it, never a public one.
+ expect(await decide("desktop", "example.com:443", ["198.18.0.1"])).toBe("rebinding");
+ expect(await decide("desktop", "198.18.0.1:8080", ["198.18.0.1"])).toBeNull();
+ for (const host of ["server", "cloud"] as const) {
+ expect(await decide(host, "example.com:443", ["198.18.0.7"], { allowed: () => true }), host).toBe("reserved");
+ }
+ });
+
it("lets a server reach only the loopback ports a bot's own processes opened, or that an admin allowed", async () => {
expect(await decide("server", "localhost:3000", ["127.0.0.1"])).toBeNull();
expect(await decide("server", "localhost:3001", ["127.0.0.1"])).toBe("this-computer");
diff --git a/server/browser/egress/policy.ts b/server/browser/egress/policy.ts
index f84fe80b0a..da822223f6 100644
--- a/server/browser/egress/policy.ts
+++ b/server/browser/egress/policy.ts
@@ -3,7 +3,7 @@
import { BlockList, isIP } from "node:net";
import { z } from "zod";
-import { addressClass, ownAddresses, type AddressClass } from "../../../electron/egress-addresses.mjs";
+import { addressClass, listed, ownAddresses, type AddressClass } from "../../../electron/egress-addresses.mjs";
export { addressClass, ownAddresses, type AddressClass };
@@ -29,6 +29,10 @@ export const REFUSAL_TEXT: Record<Refusal, string> = {
const family = (address: string) => (isIP(address) === 6 ? "ipv6" : "ipv4");
+/** Clash, Surge and other proxies in TUN + fake-IP mode answer every name from 198.18.0.0/15 and route it themselves. */
+const FAKE_IP = new BlockList();
+FAKE_IP.addSubnet("198.18.0.0", 15, "ipv4");
+
/** An address literal, or a name RFC 6761 and Chrome resolve to loopback themselves. */
export function namesThisMachine(host: string): boolean {
return isIP(host) !== 0 || /^(?:[^.]+\.)*localhost\.?$/i.test(host);
@@ -103,7 +107,9 @@ export async function refusalFor(
): Promise<Refusal | null> {
const { host, port } = target;
for (const { address } of addresses) {
- const kind = addressClass(address, own);
+ let kind = addressClass(address, own);
+ // On the desktop these come from the person's own proxy: the local network, unless this computer holds the address.
+ if (kind === "reserved" && rules.host === "desktop" && listed(FAKE_IP, address)) kind = listed(own, address) ? "this-machine" : "private";
if (kind === "public") continue;
if (kind === "metadata" || kind === "link-local" || kind === "reserved") return kind;
if (kind === "private") {