Skip to content

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

Fix: no phone QR for an address the phone app refuses

aivsomkar7479711c3d76
diff --git a/apps/docs/content/docs/self-hosting/networking.mdx b/apps/docs/content/docs/self-hosting/networking.mdx
index b800ec1b50..49a635699e 100644
--- a/apps/docs/content/docs/self-hosting/networking.mdx
+++ b/apps/docs/content/docs/self-hosting/networking.mdx
@@ -23,7 +23,7 @@ Never forward the harness port yourself. A self-hosted server is reached through
- `--lan`: this network only, plain http. It listens on every address, but answers only connections whose two ends are both private;
- `--tunnel`: a free MausBot web address.
-Each prints one pairing link; paste it into the desktop app under **+ → Connect to another computer**. The app accepts plain http only on private networks: LAN addresses, Tailscale's 100.64/10 and `*.ts.net`, and `*.local`.
+Each prints one pairing link; paste it into the desktop app under **+ → Connect to another computer**. The app accepts plain http only on private networks: LAN addresses, Tailscale's 100.64/10 and `*.ts.net`, and `*.local`. The phone app is stricter. Over plain http it takes LAN addresses, `*.ts.net` and `*.local`, but not a 100.64/10 address, a bare machine name or a `*.home.arpa` name, so the server shows no phone QR for those. On a tailnet, use `--tailscale`, which links to the machine's `.ts.net` name.
A loopback request counts as the owner only when it really comes from this machine; a LAN client that writes `Host: 127.0.0.1` is still a stranger. For webhook delivery, proxy only the dedicated webhook receiver. Never forward the main harness port to the public internet.
diff --git a/packages/phone-protocol/src/pairing-code.ts b/packages/phone-protocol/src/pairing-code.ts
index 5eb81292da..75ca8e44db 100644
--- a/packages/phone-protocol/src/pairing-code.ts
+++ b/packages/phone-protocol/src/pairing-code.ts
@@ -107,3 +107,29 @@ export function readPairingInput(raw: string): PairingInput {
}
return { kind: "code", code };
}
+
+const IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
+
+/** Whether the phone app pairs over this server link, the same check phone-core's `serverTransportAllowed` makes
+ * before dialling: https anywhere, plain http only to localhost, `*.local`, `*.ts.net` or a home-network address. iOS
+ * counts Tailscale's 100.64/10 as public and refuses plain http to it, so a tailnet uses its `.ts.net` name. */
+export function phoneAppAcceptsLink(link: string): boolean {
+ let url: URL;
+ try {
+ url = new URL(link);
+ } catch {
+ return false;
+ }
+ if (url.protocol === "https:") return true;
+ if (url.protocol !== "http:") return false;
+ const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.+$/, "");
+ if (host === "localhost" || host.endsWith(".local") || host.endsWith(".ts.net")) return true;
+ const ipv4 = IPV4.exec(host);
+ if (ipv4) {
+ const [a = 0, b = 0] = ipv4.slice(1).map(Number);
+ return a === 127 || a === 10 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168);
+ }
+ if (host === "::1") return true;
+ const first = host.includes(":") ? Number.parseInt(host.split(":")[0] ?? "", 16) : Number.NaN;
+ return Number.isFinite(first) && ((first & 0xffc0) === 0xfe80 || (first & 0xffc0) === 0xfec0 || (first & 0xfe00) === 0xfc00);
+}
diff --git a/server/cli-pairing.ts b/server/cli-pairing.ts
index 479b00540e..f33f4967f9 100644
--- a/server/cli-pairing.ts
+++ b/server/cli-pairing.ts
@@ -2,6 +2,7 @@
// owner just by being here, so it signs in once with the link printed for it.
import qrcode from "qrcode-terminal";
+import { phoneAppAcceptsLink } from "../packages/phone-protocol/src/pairing-code.ts";
import { cliCommand } from "./cli-invocation.ts";
import type { PhoneRelayStatus } from "./phone-relay.ts";
@@ -48,12 +49,17 @@ export function pairingBlock(input: {
return lines.join("\n");
}
const scanInvite = input.phone === "android" && Boolean(input.inviteUrl);
+ const appRefuses = !scanInvite && !phoneAppAcceptsLink(input.link);
lines.push(`Link ${input.link}`);
lines.push("");
lines.push(" Desktop app + → Connect to another computer, paste the link");
- lines.push(scanInvite ? " Phone scan this with the MausBot app" : " Phone scan with your camera or the MausBot app");
+ lines.push(scanInvite ? " Phone scan this with the MausBot app" : appRefuses ? " Phone scan with your camera to open it in the browser" : " Phone scan with your camera or the MausBot app");
lines.push("");
lines.push(qrToString(scanInvite ? input.inviteUrl! : input.link));
+ if (appRefuses) {
+ lines.push(`The MausBot app can't connect to ${new URL(input.link).host}. It needs HTTPS, a home Wi-Fi address or a .ts.net name:`);
+ lines.push(`give this server an https:// address, or use ${input.prefix} serve --lan or ${input.prefix} serve --tailscale in place of this one.`);
+ }
if (!input.chatOnly) lines.push(`For a phone (chat and approvals only) ${input.prefix} pair --phone`);
return lines.join("\n");
}
diff --git a/src/components/ServerPairingCard.tsx b/src/components/ServerPairingCard.tsx
index 6d597f1532..839a9aa3bd 100644
--- a/src/components/ServerPairingCard.tsx
+++ b/src/components/ServerPairingCard.tsx
@@ -19,6 +19,7 @@ import { cn } from "@/lib/cn";
import { TeamPhoneCard } from "./TeamPhoneCard";
import { ComputerNameRow } from "./ComputerNameRow";
import { isPrivateHost, serverTransport } from "../../electron/server-address.mjs";
+import { phoneAppAcceptsLink } from "../../packages/phone-protocol/src/pairing-code.ts";
export interface PairingOffer {
id: string;
@@ -72,6 +73,17 @@ export function sameWifiOnlyLink(url: string | null): boolean {
}
}
+/** The address in a phone pairing link the phone app refuses (plain http to a Tailscale IP, a bare machine name or a
+ * `.home.arpa` name), so no phone QR is shown for it; null when the app takes the link or there is none. */
+export function phoneRefusedHost(url: string | null): string | null {
+ if (!url || phoneAppAcceptsLink(url)) return null;
+ try {
+ return new URL(url).host;
+ } catch {
+ return null;
+ }
+}
+
/** The link another computer pastes into Connect to another computer, and the address it names: the server's own link, else one made from the shared address. */
export function computerLink(offer: Pick<PairingOffer, "url" | "code">, address: string | null): { link: string; address: string } | null {
const link = offer.url ?? (address ? `${address}/pair#code=${offer.code}` : null);
@@ -203,7 +215,9 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =
// A code for another computer is typed there, so the phone-only parts (QR, phone notes) stay out.
const secretNote = offer && !forComputer ? phoneSecretNote(offer) : null;
- const sameWifiOnly = !forComputer && sameWifiOnlyLink(offer?.url ?? null);
+ const refusedHost = forComputer ? null : phoneRefusedHost(offer?.url ?? null);
+ const phoneUrl = refusedHost ? null : offer?.url ?? null;
+ const sameWifiOnly = !forComputer && !refusedHost && sameWifiOnlyLink(offer?.url ?? null);
const offerPanel = pairingCodes && offer ? (
<Layer modal>
<div role="dialog" aria-modal="true" aria-label={dialogTitle} data-settings-look="simple" data-pair-dialog="code"
@@ -215,17 +229,18 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =
) : (
<div className="flex flex-col items-start gap-4">
{/* The code is the dialog's centre: the QR sits in the middle, and the words under it run the full width. */}
- {offer.url && !forComputer ? (
+ {phoneUrl && !forComputer ? (
<div data-pair-qr="" className="self-center rounded-[12px] bg-white p-3 shadow-[inset_0_0_0_0.5px_var(--settings-edge)]">
- <QRCodeSVG value={offer.url} size={200} level="M" bgColor="#ffffff" fgColor="#111111" />
+ <QRCodeSVG value={phoneUrl} size={200} level="M" bgColor="#ffffff" fgColor="#111111" />
</div>
) : null}
{/* One 14/20 ink instruction, then 12/16 secondary notes. */}
<div className="flex flex-col gap-1" data-pair-instructions="">
- {forComputer ? <p className="text-[14px] leading-5 text-ink">{t("devices.computers.typeCodeOther", { app: productName() })}</p> : offer.url ? <>
+ {forComputer ? <p className="text-[14px] leading-5 text-ink">{t("devices.computers.typeCodeOther", { app: productName() })}</p> : phoneUrl ? <>
<p className="text-[14px] leading-5 text-ink">{t("phone.code.installAndScan", { app: productName() })}</p>
<p className="text-[12px] leading-4 text-ink-secondary">{t("phone.code.notCamera", { app: productName() })}</p>
- </> : <p className="text-[14px] leading-5 text-ink">{t("phone.code.typeThis", { app: productName() })}</p>}
+ </> : refusedHost ? <p data-pair-app-refuses="" className="text-[14px] leading-5 text-ink">{t("phone.code.appRefusesAddress", { app: productName(), host: refusedHost })}</p>
+ : <p className="text-[14px] leading-5 text-ink">{t("phone.code.typeThis", { app: productName() })}</p>}
</div>
{forOtherComputer && (
<div className="flex flex-col gap-1">
@@ -238,7 +253,7 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =
<div className="text-[20px] font-medium leading-7 tracking-[0.08em] text-ink tabular-nums" data-pairing-code="">{offer.code}</div>
<div className="text-[12px] leading-4 text-ink-secondary">{codeUntil(offer.expiresAt)}</div>
</div>
- {forComputer && !cloudHome ? null : <p className="text-[12px] leading-4 text-ink-secondary">{t(cloudHome ? "phone.pair.cloudPersonal" : "remote.serverPairing.subtitle", { app: productName() })}</p>}
+ {(forComputer && !cloudHome) || refusedHost ? null : <p className="text-[12px] leading-4 text-ink-secondary">{t(cloudHome ? "phone.pair.cloudPersonal" : "remote.serverPairing.subtitle", { app: productName() })}</p>}
{secretNote ? <p data-pair-no-phone-secrets="" className="text-[12px] leading-4 text-ink-secondary">{secretNote}</p> : null}
{sameWifiOnly ? <p data-pair-same-wifi="" className="text-[12px] leading-4 text-ink-secondary">{t("remote.serverPairing.sameWifiOnly", { app: productName() })}</p> : null}
</div>
diff --git a/src/components/devices/PairCodePanel.tsx b/src/components/devices/PairCodePanel.tsx
index 39f7ebb379..7810cd9676 100644
--- a/src/components/devices/PairCodePanel.tsx
+++ b/src/components/devices/PairCodePanel.tsx
@@ -9,7 +9,7 @@ import type { SessionState } from "@/lib/session";
import { readSharedSessionState } from "@/lib/shared-session";
import { api } from "@/state/api";
import { useStoreSelector } from "@/state/store-select";
-import { canPairDevices, computerLink, pairingBlockedReason, phoneSecretNote, sameWifiOnlyLink, type PairingOffer } from "../ServerPairingCard";
+import { canPairDevices, computerLink, pairingBlockedReason, phoneRefusedHost, phoneSecretNote, sameWifiOnlyLink, type PairingOffer } from "../ServerPairingCard";
import { Select } from "../Select";
import { TeamPhoneCard } from "../TeamPhoneCard";
import { PhoneCodeCard, TypedCode, Waiting } from "./CodeCard";
@@ -180,6 +180,7 @@ export function PairCodePanel({ kind, address, onConnected, cloudHome = false, a
}
if (kind === "phone") {
const secretNote = phoneSecretNote(offer);
+ const refusedHost = phoneRefusedHost(offer.url);
const notes = <>
{link && <button type="button" onClick={copy} data-copy-link="" className="ui-button ui-button-sm w-fit">
{t(copied === "copied" ? "remote.serverPairing.copied" : copied === "failed" ? "common.copyFailed" : "remote.serverPairing.copyLink")}
@@ -189,13 +190,15 @@ export function PairCodePanel({ kind, address, onConnected, cloudHome = false, a
<option value="admin">{t("remote.serverPairing.scope.admin")}</option>
<option value="client">{t("remote.serverPairing.scope.client")}</option>
</Select>}
- <p className="text-[12px] leading-4 text-ink-secondary">{t(cloudHome ? "phone.pair.cloudPersonal" : "remote.serverPairing.subtitle", { app: productName() })}</p>
+ {!refusedHost && <p className="text-[12px] leading-4 text-ink-secondary">{t(cloudHome ? "phone.pair.cloudPersonal" : "remote.serverPairing.subtitle", { app: productName() })}</p>}
{secretNote && <p data-pair-no-phone-secrets="" className="text-[12px] leading-4 text-ink-secondary">{secretNote}</p>}
- {sameWifiOnlyLink(offer.url) && <p data-pair-same-wifi="" className="text-[12px] leading-4 text-ink-secondary">{t("remote.serverPairing.sameWifiOnly", { app: productName() })}</p>}
+ {!refusedHost && sameWifiOnlyLink(offer.url) && <p data-pair-same-wifi="" className="text-[12px] leading-4 text-ink-secondary">{t("remote.serverPairing.sameWifiOnly", { app: productName() })}</p>}
</>;
- if (link) return <PhoneCodeCard link={link.link} code={offer.code} expiresAt={offer.expiresAt} connected={connected}>{notes}</PhoneCodeCard>;
+ if (link && !refusedHost) return <PhoneCodeCard link={link.link} code={offer.code} expiresAt={offer.expiresAt} connected={connected}>{notes}</PhoneCodeCard>;
return <div className="flex flex-col gap-3" data-pair-panel="phone">
- <p className="text-[13px] leading-[18px] text-ink">{t("phone.code.typeIntro", { app: productName() })}</p>
+ {refusedHost
+ ? <p data-pair-app-refuses="" className="text-[13px] leading-[18px] text-ink">{t("phone.code.appRefusesAddress", { app: productName(), host: refusedHost })}</p>
+ : <p className="text-[13px] leading-[18px] text-ink">{t("phone.code.typeIntro", { app: productName() })}</p>}
<TypedCode label={t("connect.code")} code={offer.code} expiresAt={offer.expiresAt} />
<Waiting connected={connected} waiting={t("devicesPage.addFlow.waitingPhone")} />
{notes}
diff --git a/src/locales/en.json b/src/locales/en.json
index cf38252006..38eb62325c 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -5144,6 +5144,7 @@
"phone.code.title": "Scan or enter the code",
"phone.code.installAndScan": "Install {app} on your phone from the App Store or Google Play, then scan this code in the app.",
"phone.code.notCamera": "Scan it from inside the {app} app, not the camera.",
+ "phone.code.appRefusesAddress": "The {app} app can't connect to {host}. It needs an HTTPS address, a home Wi-Fi address like 192.168.1.20, or a Tailscale name ending in .ts.net. Open this page at one of those, then make a new code.",
"phone.code.expiredDetail": "Create a fresh code when the other device is ready.",
"phone.code.qrAria": "Device pairing QR code",
"phone.code.createNew": "Create a new code",