Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Self-hosted pairing: say secrets go on the web, not "reopen the app"
AdityaUmale4b3c417309e9
diff --git a/server/index.ts b/server/index.tsindex f8906fd387..f242138820 100644--- a/server/index.ts+++ b/server/index.ts@@ -1484,7 +1484,7 @@ const browserCleanup: BrowserCleanupCoordinator = new BrowserCleanupCoordinator(return true;},});-const phoneSecrets = new PhoneSecretBridge(postDesktopPrivateMessage);+const phoneSecrets = new PhoneSecretBridge(postDesktopPrivateMessage, undefined, undefined, DESKTOP_MANAGED);utilityParentPort?.on("message", (event) => {const message = event?.data;try {@@ -12786,6 +12786,8 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {url: base ? `${base}/pair#code=${code}` : null,inviteUrl: invite,serverName, ...(phoneRelay ? { relay: phoneRelay.status() } : {}),+ // False until a desktop app hands this server its phone key; a self-hosted server never gets one.+ phoneSecrets: phoneSecrets.ready,hint: base? null: "this server has no public address to put in a link: set OMB_PUBLIC_URL, or open /pair on the address you use and type the code",diff --git a/server/phone-secret.test.ts b/server/phone-secret.test.tsindex 31a77cfa66..e5c4ca3632 100644--- a/server/phone-secret.test.ts+++ b/server/phone-secret.test.ts@@ -175,6 +175,21 @@ describe("PhoneSecretBridge", () => {})).rejects.toEqual(expect.objectContaining<Partial<PhoneSecretError>>({ status: 503 }));});+ it("tells a self-hosted server's phone to use the web, and is ready only once a desktop key arrives", async () => {+ const context = { ...baseContext("AAAAAAAAAAAAAAAAAAAAAA"), encapsulatedKey: "A".repeat(87), ciphertext: "A".repeat(24) };+ const selfHosted = new PhoneSecretBridge(() => true, 50, 8, false);+ expect(selfHosted.ready).toBe(false);+ await expect(selfHosted.provide(context)).rejects.toMatchObject({+ status: 503,+ message: "This server cannot take secrets from a phone. Enter it on the web or on your computer instead.",+ });++ const desktop = new PhoneSecretBridge(() => true, 50);+ await expect(desktop.provide(context)).rejects.toMatchObject({ message: expect.stringContaining("Reopen OpenMausBot") });+ desktop.receive((await keyMaterial()).message);+ expect(desktop.ready).toBe(true);+ });+it("rejects a private scalar that does not match the advertised public point", async () => {const material = await keyMaterial();const other = await keyMaterial();diff --git a/server/phone-secret.ts b/server/phone-secret.tsindex 1ff6f3a022..2b3bbe2dbc 100644--- a/server/phone-secret.ts+++ b/server/phone-secret.ts@@ -319,18 +319,27 @@ export class PhoneSecretBridge {private readonly send: SendPrivateMessage;private readonly timeoutMs: number;private readonly maximumPending: number;+ private readonly desktopManaged: boolean;constructor(send: SendPrivateMessage,// Outlives every provider's validation deadline but stays below the HTTPS proxy and phone deadlines (Cloudflare's boundary).timeoutMs = 90_000,maximumPending = 8,+ /** False on a self-hosted server: no desktop app ever hands it a key, so reopening the app cannot help. */+ desktopManaged = true,) {this.send = send;+ this.desktopManaged = desktopManaged;this.timeoutMs = timeoutMs;this.maximumPending = maximumPending;}+ /** Whether a phone can seal a secret for this computer: only after the desktop app has handed over its key. */+ get ready(): boolean {+ return this.identity !== null;+ }+receive(raw: unknown): boolean {const message = (raw as { data?: unknown } | null)?.data ?? raw;if (!message || typeof message !== "object" || Array.isArray(message)) return false;@@ -375,7 +384,9 @@ export class PhoneSecretBridge {private async openWithinLimit(context: PhoneSecretContext): Promise<string> {if (!this.identity) {throw new PhoneSecretError(- "Secure phone entry is not ready on this computer. Reopen OpenMausBot and try again.",+ this.desktopManaged+ ? "Secure phone entry is not ready on this computer. Reopen OpenMausBot and try again."+ : "This server cannot take secrets from a phone. Enter it on the web or on your computer instead.",503,);}diff --git a/src/components/ServerPairingCard.test.ts b/src/components/ServerPairingCard.test.tsindex 65d87e60b3..bea42a8763 100644--- a/src/components/ServerPairingCard.test.ts+++ b/src/components/ServerPairingCard.test.ts@@ -3,7 +3,7 @@ import { renderToStaticMarkup } from "react-dom/server";import { describe, expect, it } from "vitest";import { codeUntil, lastSeen } from "../lib/pairing-time";-import { canPairDevices, pairingBlockedReason, ServerPairingCard, shownDevices } from "./ServerPairingCard";+import { canPairDevices, pairingBlockedReason, phoneSecretNote, ServerPairingCard, shownDevices } from "./ServerPairingCard";describe("pairing devices from a hosted server's settings", () => {it("is offered to the owner on the box and to admin sessions, never to chat-only sessions", () => {@@ -87,4 +87,10 @@ describe("pairing devices from a hosted server's settings", () => {expect(shownDevices(devices, true).map((device) => device.id)).toEqual(["a"]);expect(shownDevices(devices, false).map((device) => device.id)).toEqual(["a", "b"]);});++ it("says under the code that secrets go on the web when the server has no phone key, and nothing otherwise", () => {+ expect(phoneSecretNote({ phoneSecrets: false })).toBe("This phone can chat and approve here, but secrets must be entered on the web or computer.");+ expect(phoneSecretNote({ phoneSecrets: true })).toBeNull();+ expect(phoneSecretNote({})).toBeNull();+ });});diff --git a/src/components/ServerPairingCard.tsx b/src/components/ServerPairingCard.tsxindex 4065ff8d1c..05d1ef67a2 100644--- a/src/components/ServerPairingCard.tsx+++ b/src/components/ServerPairingCard.tsx@@ -24,6 +24,8 @@ export interface PairingOffer {expiresAt: number;url: string | null;hint: string | null;+ /** False when this server has no phone key, so a paired phone cannot enter secrets here. Absent on older servers. */+ phoneSecrets?: boolean;}export interface PairedDevice {@@ -47,6 +49,11 @@ export function pairingBlockedReason(state: SessionState | null): "chat-only" |return state?.kind === "session" && !state.scopes.includes("admin") ? "chat-only" : null;}+/** The line a pairing code shows when the phone will not be able to enter secrets on this server. */+export function phoneSecretNote(offer: Pick<PairingOffer, "phoneSecrets">): string | null {+ return offer.phoneSecrets === false ? t("remote.serverPairing.noPhoneSecrets") : null;+}+export function shownDevices(devices: PairedDevice[], cloudHome: boolean): PairedDevice[] {return cloudHome ? devices.filter((device) => device.scopes.includes("admin")) : devices;}@@ -161,6 +168,7 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =if (result !== "empty") setCopied(result);}+ const secretNote = offer ? phoneSecretNote(offer) : null;const offerPanel = pairingCodes && offer ? (<Layer modal><div role="dialog" aria-modal="true" aria-label={t("phone.pair.dialogTitle", { place: placeName })} data-settings-look="simple" data-pair-dialog="code"@@ -189,6 +197,7 @@ export function ServerPairingCard({ initialSession = null, initialPairingCodes =<div className="text-[12px] leading-4 text-ink-secondary">{codeUntil(offer.expiresAt)}</div></div><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}</div>)}<div className="flex items-center justify-end gap-2">diff --git a/src/locales/en.json b/src/locales/en.jsonindex bf963b7654..051a86dab9 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -6080,6 +6080,7 @@"settings.domain.failed": "The domain could not be updated. Check DNS and HTTPS, then try again.","remote.serverPairing.title": "Pair a phone or another computer","remote.serverPairing.subtitle": "Create a one-time code, then scan it with the {app} app or open the link in a browser. Codes work once and expire after five minutes.",+ "remote.serverPairing.noPhoneSecrets": "This phone can chat and approve here, but secrets must be entered on the web or computer.","remote.serverPairing.scope.admin": "Full access","remote.serverPairing.scope.client": "Chat and approvals only","remote.serverPairing.create": "Create pairing code",