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(app): block outside web pages from Tauri plugins
Manas Raghuwanshib300de990e74
diff --git a/.github/workflows/test-frontend.yml b/.github/workflows/test-frontend.ymlindex 765aa5d3f..d8b45eb54 100644--- a/.github/workflows/test-frontend.yml+++ b/.github/workflows/test-frontend.yml@@ -19,6 +19,8 @@ on:- 'apps/screenpipe-app-tauri/bun.lock'- 'apps/screenpipe-app-tauri/vitest.config.ts'- 'apps/screenpipe-app-tauri/tsconfig*.json'+ - 'apps/screenpipe-app-tauri/src-tauri/capabilities/**'+ - 'apps/screenpipe-app-tauri/src-tauri/tauri*.conf.json'- '.github/workflows/test-frontend.yml'pull_request:paths:@@ -34,6 +36,8 @@ on:- 'apps/screenpipe-app-tauri/bun.lock'- 'apps/screenpipe-app-tauri/vitest.config.ts'- 'apps/screenpipe-app-tauri/tsconfig*.json'+ - 'apps/screenpipe-app-tauri/src-tauri/capabilities/**'+ - 'apps/screenpipe-app-tauri/src-tauri/tauri*.conf.json'- '.github/workflows/test-frontend.yml'concurrency:diff --git a/apps/screenpipe-app-tauri/components/__tests__/markdown-web-link.test.tsx b/apps/screenpipe-app-tauri/components/__tests__/markdown-web-link.test.tsxnew file mode 100644index 000000000..c3301731b--- /dev/null+++ b/apps/screenpipe-app-tauri/components/__tests__/markdown-web-link.test.tsx@@ -0,0 +1,45 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com++// Daily summaries and meeting notes render AI-written markdown with the+// default anchor. A plain web link there loads the site inside the app window,+// so web links must open in the system browser: the opener plugin does that+// for `_blank` http(s) clicks.++import React from "react";+import { describe, expect, it, vi } from "vitest";+import { render, screen } from "@testing-library/react";++vi.mock("@/lib/utils/tauri", () => ({+ commands: {+ openViewerWindow: vi.fn(async () => ({ status: "ok" })),+ },+}));++vi.mock("@/components/rewind/media", () => ({+ MediaComponent: () => null,+}));++import { MemoizedReactMarkdown, chatUrlTransform } from "@/components/markdown";++function renderLink(markdown: string): HTMLElement {+ render(<MemoizedReactMarkdown urlTransform={chatUrlTransform}>{markdown}</MemoizedReactMarkdown>);+ return screen.getByRole("link");+}++describe("MemoizedReactMarkdown web links", () => {+ it.each(["https://example.com/a", "http://example.com/a", "HTTPS://example.com/a"])(+ "opens %s outside the app window",+ (href) => {+ const link = renderLink(`[site](${href})`);+ expect(link.getAttribute("target")).toBe("_blank");+ expect(link.getAttribute("rel")).toBe("noopener noreferrer");+ },+ );++ it.each(["screenpipe://frame/123", "#notes"])("leaves %s to the app", (href) => {+ const link = renderLink(`[in app](${href})`);+ expect(link.getAttribute("href")).toBe(href);+ expect(link.hasAttribute("target")).toBe(false);+ });+});diff --git a/apps/screenpipe-app-tauri/components/markdown.tsx b/apps/screenpipe-app-tauri/components/markdown.tsxindex 0e25070df..1351ea06f 100644--- a/apps/screenpipe-app-tauri/components/markdown.tsx+++ b/apps/screenpipe-app-tauri/components/markdown.tsx@@ -175,7 +175,12 @@ export function createMediaAwareMarkdownComponents(return <CustomAnchor href={href} {...props}>{children}</CustomAnchor>;}- return <a href={href} {...props}>{children}</a>;+ // A plain web link would load the site inside the app window. The opener+ // plugin sends `_blank` http(s) clicks to the system browser instead.+ const webLink = href && /^https?:/i.test(href)+ ? { target: "_blank", rel: "noopener noreferrer" }+ : {};+ return <a href={href} {...props} {...webLink}>{children}</a>;},img({ src, alt, ...props }) {if (!src) return null;diff --git a/apps/screenpipe-app-tauri/e2e/COVERAGE.md b/apps/screenpipe-app-tauri/e2e/COVERAGE.mdindex 9595cf84e..a4a80ee41 100644--- a/apps/screenpipe-app-tauri/e2e/COVERAGE.md+++ b/apps/screenpipe-app-tauri/e2e/COVERAGE.md@@ -10,9 +10,9 @@ and layer declared in the manifest, weighted by confidence and criticality.- Manifest: `e2e/coverage-map.json`- Specs directory: `e2e/specs`-- Mapped specs: 142-- Declared test blocks: 411-- Weighted coverage points: 331.5+- Mapped specs: 143+- Declared test blocks: 414+- Weighted coverage points: 334.5Confidence weights: strong=1.0, partial=0.7, conditional=0.4, smoke=0.3.Criticality weights: high=1.0, medium=0.7, low=0.4.@@ -23,9 +23,9 @@ can execute more runtime cases than this number shows.| Platform | Specs | Declared tests | Weighted points | Layers | Features | Critical score || --- | --- | --- | --- | --- | --- | --- |-| windows | 108 | 348 | 291.1 | 15 | 123 | 85% |-| macos | 138 | 373 | 301.3 | 17 | 133 | 88% |-| linux | 96 | 306 | 260.5 | 14 | 120 | 80% |+| windows | 109 | 351 | 294.1 | 15 | 124 | 85% |+| macos | 139 | 376 | 304.3 | 17 | 134 | 88% |+| linux | 97 | 309 | 263.5 | 14 | 121 | 80% |## Runtime Results@@ -51,8 +51,8 @@ pass/fail/skip counts.| pipes | 6 specs / 20 tests / 20.0 pts | 8 specs / 26 tests / 26.0 pts | 6 specs / 20 tests / 20.0 pts || real-ui-e2e | 80 specs / 241 tests / 204.9 pts | 98 specs / 260 tests / 220.3 pts | 74 specs / 217 tests / 190.9 pts || settings | 15 specs / 42 tests / 39.0 pts | 17 specs / 36 tests / 31.7 pts | 14 specs / 33 tests / 30.0 pts |-| storage-privacy | 10 specs / 44 tests / 35.3 pts | 10 specs / 29 tests / 28.1 pts | 7 specs / 22 tests / 21.1 pts |-| tauri-command | 24 specs / 69 tests / 55.9 pts | 36 specs / 92 tests / 74.3 pts | 23 specs / 70 tests / 56.8 pts |+| storage-privacy | 11 specs / 47 tests / 38.3 pts | 11 specs / 32 tests / 31.1 pts | 8 specs / 25 tests / 24.1 pts |+| tauri-command | 25 specs / 72 tests / 58.9 pts | 37 specs / 95 tests / 77.3 pts | 24 specs / 73 tests / 59.8 pts || window-lifecycle | 22 specs / 71 tests / 59.5 pts | 23 specs / 55 tests / 40.9 pts | 16 specs / 44 tests / 34.4 pts |## Critical Feature Matrix@@ -234,6 +234,7 @@ pass/fail/skip counts.| tray-search.spec.ts | windows, macos, linux | window-lifecycle, tauri-command, real-ui-e2e | tray-search, home-search, window-lifecycle | high | partial | command | 2 | Invokes open_search_window and verifies focused floating Search. || updater-banner.spec.ts | windows, macos, linux | real-ui-e2e, settings | update-surfacing, settings-persistence | high | partial | mixed | 2 | Synthetic update-available event surfaces the restart-to-update banner. A real Auto-update toggle plus delayed store save verifies restart waits for preference persistence and survives settings-store re-hydration; an E2E-only handoff suppresses the destructive relaunch. Real check/download/install + rollback stay manual via e2e/mock-updates because the debug E2E build disables updater checks. || viewer-deeplink.spec.ts | windows, macos, linux | window-lifecycle, tauri-command | viewer-deeplink, window-lifecycle | medium | partial | command | 3 | Viewer window creation and per-path dedupe. |+| webview-remote-ipc.spec.ts | windows, macos, linux | tauri-command, storage-privacy | webview-remote-ipc | high | strong | command | 3 | Loads a page from another localhost port in the Home window, which the old remote capability trusted. The IPC bridge is still injected there, but fs and store calls are rejected by the ACL and create nothing; the same fs call from the app's own page still works. || webview-shell-scope.spec.ts | windows, macos, linux | tauri-command, os-integration | webview-shell-scope, ai-tools | high | strong | command | 5 | Calls the shell plugin from a real app webview. The removed exec-sh, sh, cmd and any-argument open entries are rejected by the capability scope. On macOS, a caller-supplied PATH cannot replace the system launcher, and the Claude/Cursor install check still reaches fs exists. || window-activation.spec.ts | macos | window-lifecycle, tauri-command, real-ui-e2e | window-lifecycle, chat | medium | conditional | real-user-flow | 2 | macOS-only show_window_activated focus coverage. || window-lifecycle.spec.ts | windows, macos, linux | window-lifecycle, tauri-command, real-ui-e2e | window-lifecycle, onboarding, tray-search | high | strong | mixed | 3 | Home, Search, and onboarding window routing. |diff --git a/apps/screenpipe-app-tauri/e2e/coverage-map.json b/apps/screenpipe-app-tauri/e2e/coverage-map.jsonindex 0a591d986..42f6a1ac9 100644--- a/apps/screenpipe-app-tauri/e2e/coverage-map.json+++ b/apps/screenpipe-app-tauri/e2e/coverage-map.json@@ -2966,6 +2966,25 @@"ux": "command","notes": "Calls the shell plugin from a real app webview. The removed exec-sh, sh, cmd and any-argument open entries are rejected by the capability scope. On macOS, a caller-supplied PATH cannot replace the system launcher, and the Claude/Cursor install check still reaches fs exists."},+ {+ "spec": "webview-remote-ipc.spec.ts",+ "platforms": [+ "windows",+ "macos",+ "linux"+ ],+ "layers": [+ "tauri-command",+ "storage-privacy"+ ],+ "features": [+ "webview-remote-ipc"+ ],+ "criticality": "high",+ "confidence": "strong",+ "ux": "command",+ "notes": "Loads a page from another localhost port in the Home window, which the old remote capability trusted. The IPC bridge is still injected there, but fs and store calls are rejected by the ACL and create nothing; the same fs call from the app's own page still works."+ },{"spec": "window-activation.spec.ts","platforms": [diff --git a/apps/screenpipe-app-tauri/e2e/specs/webview-remote-ipc.spec.ts b/apps/screenpipe-app-tauri/e2e/specs/webview-remote-ipc.spec.tsnew file mode 100644index 000000000..eb00e9cbc--- /dev/null+++ b/apps/screenpipe-app-tauri/e2e/specs/webview-remote-ipc.spec.ts@@ -0,0 +1,117 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com++import { existsSync, rmSync } from "node:fs";+import { createServer, type Server } from "node:http";+import type { AddressInfo } from "node:net";+import { homedir } from "node:os";+import { join } from "node:path";+import { openHomeWindow, t, waitForAppReady } from "../helpers/test-utils.js";++// Tauri injects its IPC bridge into every page, including outside websites+// that end up in an app window (a clicked link, the agent browser, a login+// window). Only the app's own pages may reach plugins. This loads a page from+// another localhost port, which the old `http://localhost:*` remote entry+// trusted, and calls plugins from it.++// `failure`, not `error`: tauri-plugin-webdriver reports a script result that+// carries a string `error` field as a WebDriver error.+type InvokeResult = { ok: boolean; value: unknown; failure: string };++async function invoke(command: string, args: Record<string, unknown>): Promise<InvokeResult> {+ return (await browser.executeAsync(+ (cmd: string, payload: Record<string, unknown>, done: (result: InvokeResult) => void) => {+ const internals = (window as unknown as {+ __TAURI_INTERNALS__?: { invoke: (c: string, a: unknown) => Promise<unknown> };+ }).__TAURI_INTERNALS__;+ if (!internals) {+ done({ ok: false, value: null, failure: "no tauri internals" });+ return;+ }+ internals+ .invoke(cmd, payload)+ .then((value) => done({ ok: true, value, failure: "" }))+ .catch((error) => done({ ok: false, value: null, failure: String(error) }));+ },+ command,+ args,+ )) as InvokeResult;+}++async function navigate(url: string): Promise<void> {+ await browser.execute((target: string) => {+ window.location.href = target;+ }, url);+ await browser.waitUntil(+ async () => {+ try {+ return (await browser.execute(+ (target: string) => window.location.href.startsWith(target) && document.readyState === "complete",+ url,+ )) as boolean;+ } catch {+ // Transient while the old document is torn down — retry.+ return false;+ }+ },+ { timeout: t(30_000), interval: 250, timeoutMsg: `webview did not load ${url}` },+ );+}++describe("Webview remote IPC", function () {+ this.timeout(120_000);++ const marker = join(homedir(), `screenpipe-e2e-remote-ipc-${process.pid}`);+ let server: Server;+ let remoteUrl = "";+ let appUrl = "";++ before(async () => {+ rmSync(marker, { recursive: true, force: true });+ server = createServer((_request, response) => {+ response.writeHead(200, { "content-type": "text/html" });+ response.end("<!doctype html><title>remote</title><p>remote page</p>");+ });+ await new Promise<void>((resolve) => server.listen(0, resolve));+ remoteUrl = `http://localhost:${(server.address() as AddressInfo).port}/`;++ await waitForAppReady();+ await openHomeWindow();+ appUrl = await browser.getUrl();+ await navigate(remoteUrl);+ });++ after(async () => {+ rmSync(marker, { recursive: true, force: true });+ if (appUrl) await navigate(appUrl);+ await new Promise<void>((resolve) => server.close(() => resolve()));+ });++ it("still injects the IPC bridge into the remote page", async () => {+ // Without the bridge the rejections below would pass for the wrong reason.+ expect((await invoke("plugin:fs|exists", { path: marker })).failure).not.toBe("no tauri internals");+ });++ it("rejects fs and store calls from the remote page", async () => {+ const calls: [string, Record<string, unknown>][] = [+ ["plugin:fs|exists", { path: marker }],+ ["plugin:fs|read_dir", { path: homedir() }],+ ["plugin:fs|mkdir", { path: marker, options: {} }],+ ["plugin:store|load", { path: `${marker}.json`, options: {} }],+ ];+ for (const [command, args] of calls) {+ const result = await invoke(command, args);+ expect(result.ok).toBe(false);+ expect(result.failure).toMatch(/not allowed/);+ }+ expect(existsSync(marker)).toBe(false);+ expect(existsSync(`${marker}.json`)).toBe(false);+ });++ it("still allows the same fs call from the app's own page", async () => {+ await navigate(appUrl);+ const result = await invoke("plugin:fs|exists", { path: marker });+ expect(result.failure).toBe("");+ expect(result.value).toBe(false);+ });+});diff --git a/apps/screenpipe-app-tauri/lib/__tests__/webview-remote-ipc.test.ts b/apps/screenpipe-app-tauri/lib/__tests__/webview-remote-ipc.test.tsnew file mode 100644index 000000000..969af2bf2--- /dev/null+++ b/apps/screenpipe-app-tauri/lib/__tests__/webview-remote-ipc.test.ts@@ -0,0 +1,54 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com++import { describe, expect, it } from "vitest";+import { readFileSync, readdirSync } from "node:fs";+import { resolve } from "node:path";++// Tauri injects its IPC bridge into every page a webview loads, including+// outside websites in the agent browser, login windows, and the main window+// after a link click. Those pages are kept away from the fs, store, http and+// process plugins only because no capability lists a remote origin: a remote+// URL listed there gets every permission in that capability on every window.++const srcTauri = resolve(process.cwd(), "src-tauri");+const capabilitiesDir = resolve(srcTauri, "capabilities");++function rustSourceFiles(directory: string): string[] {+ return readdirSync(directory, { withFileTypes: true }).flatMap((dirent) => {+ const path = resolve(directory, dirent.name);+ if (dirent.isDirectory()) return rustSourceFiles(path);+ return dirent.name.endsWith(".rs") ? [path] : [];+ });+}++describe("webview remote IPC", () => {+ it("keeps every capability file in a format this test reads", () => {+ const files = readdirSync(capabilitiesDir);+ expect(files.length).toBeGreaterThan(0);+ expect(files.filter((file) => !file.endsWith(".json"))).toEqual([]);+ });++ it("grants no capability to remote origins", () => {+ const remote = readdirSync(capabilitiesDir).filter(+ (file) => "remote" in JSON.parse(readFileSync(resolve(capabilitiesDir, file), "utf8")),+ );+ expect(remote).toEqual([]);+ });++ it("defines no inline capabilities in any Tauri config", () => {+ const configs = readdirSync(srcTauri).filter((file) => /^tauri\.(?:.+\.)?conf\.json$/.test(file));+ expect(configs).toContain("tauri.conf.json");+ for (const file of configs) {+ const config = JSON.parse(readFileSync(resolve(srcTauri, file), "utf8"));+ expect(config.app?.security?.capabilities, file).toBeUndefined();+ }+ });++ it("adds no capability at runtime", () => {+ const callers = rustSourceFiles(resolve(srcTauri, "src")).filter((file) =>+ readFileSync(file, "utf8").includes("add_capability"),+ );+ expect(callers).toEqual([]);+ });+});diff --git a/apps/screenpipe-app-tauri/src-tauri/capabilities/main.json b/apps/screenpipe-app-tauri/src-tauri/capabilities/main.jsonindex ee5c144e1..080f14883 100644--- a/apps/screenpipe-app-tauri/src-tauri/capabilities/main.json+++ b/apps/screenpipe-app-tauri/src-tauri/capabilities/main.json@@ -5,17 +5,6 @@"windows": ["*"],- "remote": {- "urls": [- "http://localhost:*",- "https://api.openai.com/*",- "https://*.openai.com/*",- "https://api.screenpipe.com/*",- "https://*.anthropic.com/*",- "https://*.ollama.ai/*",- "https://*"- ]- },"permissions": ["core:event:allow-listen","core:event:default",diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rsindex 61c063918..36becc59a 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs@@ -17,11 +17,13 @@//!//! [`OwnedWebviewHandle`] is implemented by translating the agent's `eval`//! requests into `webview.eval()` + a `document.title` round-trip. We use-//! the title as a result transport because cross-origin pages-//! (e.g. wikipedia.org) do not have access to `window.__TAURI__` — the-//! Tauri IPC bridge is only injected on app-origin pages. Setting+//! the title as a result transport because pages loaded here must not be+//! able to call Tauri IPC. Tauri injects the IPC bridge into every page,+//! including cross-origin ones (e.g. wikipedia.org); those calls are+//! rejected only because no capability in `capabilities/` lists remote+//! URLs (`lib/__tests__/webview-remote-ipc.test.ts` enforces this). Setting//! `document.title` works on every origin and the title is observable from-//! Rust via `on_document_title_changed`. We install the bridge via+//! Rust via `on_document_title_changed`. We install that title bridge via//! `initialization_script`, which Tauri runs on every page load including//! cross-origin navigations.//!diff --git a/docs/COVERAGE.md b/docs/COVERAGE.mdindex 453a711ba..4179c3109 100644--- a/docs/COVERAGE.md+++ b/docs/COVERAGE.md@@ -24,15 +24,15 @@ results and `cargo llvm-cov` data on top when judging release confidence.### Tauri E2E-- Mapped specs: 142-- Declared test blocks: 411-- Weighted coverage points: 331.5+- Mapped specs: 143+- Declared test blocks: 414+- Weighted coverage points: 334.5| Platform | Specs | Declared tests | Weighted points | Layers | Features | Critical score || --- | --- | --- | --- | --- | --- | --- |-| windows | 108 | 348 | 291.1 | 15 | 123 | 85% |-| macos | 138 | 373 | 301.3 | 17 | 133 | 88% |-| linux | 96 | 306 | 260.5 | 14 | 120 | 80% |+| windows | 109 | 351 | 294.1 | 15 | 124 | 85% |+| macos | 139 | 376 | 304.3 | 17 | 134 | 88% |+| linux | 97 | 309 | 263.5 | 14 | 121 | 80% |### Core Engine