YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(auth): don't sign out on local-engine 401s (host match, not substring) (#4465)
Louis Beaumontaad18c86ab9c
diff --git a/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx b/apps/screenpipe-app-tauri/lib/auth-guard.test.tsxindex 9da608d2a..06cae98bb 100644--- a/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx+++ b/apps/screenpipe-app-tauri/lib/auth-guard.test.tsx@@ -35,7 +35,7 @@ vi.mock("@/components/ui/use-toast", () => ({ toast: mocks.toast }));vi.mock("@/components/ui/toast", () => ({ ToastAction: () => null }));vi.mock("@/lib/web-url", () => ({ screenpipeWebUrl: () => "https://screenpipe.com/login" }));-import { AuthGuard, shouldReverifyOnFocus } from "./auth-guard";+import { AuthGuard, isScreenpipeApi, shouldReverifyOnFocus } from "./auth-guard";const LOGGED_IN = { token: "tok-123", cloud_subscribed: false };@@ -67,6 +67,39 @@ afterEach(() => {mocks.state.user = null;});+describe("isScreenpipeApi", () => {+ it("matches the cloud API host and its subdomains", () => {+ expect(isScreenpipeApi("https://screenpipe.com/api/user")).toBe(true);+ expect(isScreenpipeApi("https://screenpi.pe/api/oauth/exchange")).toBe(true);+ expect(isScreenpipeApi("https://api.screenpipe.com/v1/chat/completions")).toBe(true);+ expect(isScreenpipeApi("https://clerk.screenpipe.com/")).toBe(true);+ });++ it("does NOT match the local engine when a screenpipe-domain email rides in the query", () => {+ // regression: a connected account on the screenpi.pe domain made the local+ // engine's 401 look like a cloud session expiry and signed the user out.+ expect(+ isScreenpipeApi(+ "http://localhost:3030/connections/google-calendar/events?hours_back=0&instance=member%40screenpi.pe"+ )+ ).toBe(false);+ expect(+ isScreenpipeApi("http://127.0.0.1:3030/connections/[email protected]")+ ).toBe(false);+ });++ it("does NOT match a third-party host that merely mentions the domain in path/query", () => {+ expect(isScreenpipeApi("https://evil.example.com/?ref=screenpi.pe")).toBe(false);+ // not a subdomain — must not match on a bare suffix+ expect(isScreenpipeApi("https://notscreenpipe.com/api")).toBe(false);+ expect(isScreenpipeApi("https://screenpipe.com.evil.com/api")).toBe(false);+ });++ it("returns false for an unparseable url", () => {+ expect(isScreenpipeApi("::::")).toBe(false);+ });+});+describe("shouldReverifyOnFocus", () => {it("allows the first verify of the session (lastVerifyAt === 0)", () => {expect(shouldReverifyOnFocus(1_000, 0, "visible", 30_000)).toBe(true);diff --git a/apps/screenpipe-app-tauri/lib/auth-guard.tsx b/apps/screenpipe-app-tauri/lib/auth-guard.tsxindex e39f2ec5c..af5bfcc60 100644--- a/apps/screenpipe-app-tauri/lib/auth-guard.tsx+++ b/apps/screenpipe-app-tauri/lib/auth-guard.tsx@@ -65,8 +65,45 @@ function showSignedOutToast() {});}-function isScreenpipeApi(url: string): boolean {- return url.includes("screenpi.pe") || url.includes("screenpipe.com");+// Only the screenpipe CLOUD API (screenpi.pe / screenpipe.com and their+// subdomains) carries the login session whose 401/403 means "signed out".+//+// Match on the URL *host* — never a substring of the whole URL. The local+// engine at localhost:3030 routinely carries a screenpipe-domain value in the+// query string (e.g. `[email protected]` for a connected account),+// and a substring match treats that local URL as the cloud API. The local+// engine's 401s are connection-level (an OAuth token that failed to refresh —+// e.g. during a transient DNS/network blip), NOT session expiry, so misreading+// them signed the user out and paused recording. This bit anyone whose+// connected-account email is @screenpi.pe / @screenpipe.com.+export function isScreenpipeApi(url: string): boolean {+ let host: string;+ try {+ const base =+ typeof window !== "undefined" && window.location?.href+ ? window.location.href+ : "http://localhost";+ host = new URL(url, base).hostname.toLowerCase();+ } catch {+ return false;+ }++ // The local engine is never the cloud auth surface.+ if (+ host === "localhost" ||+ host === "127.0.0.1" ||+ host === "::1" ||+ host === "[::1]"+ ) {+ return false;+ }++ return (+ host === "screenpi.pe" ||+ host === "screenpipe.com" ||+ host.endsWith(".screenpi.pe") ||+ host.endsWith(".screenpipe.com")+ );}export function AuthGuard({ children }: { children: React.ReactNode }) {