Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): isolate desktop web views in a dedicated session partition

Elian Doran0dd52860b117
diff --git a/apps/client/src/types-lib.d.ts b/apps/client/src/types-lib.d.ts
index c559dc6a55..59e7dbc4d9 100644
--- a/apps/client/src/types-lib.d.ts
+++ b/apps/client/src/types-lib.d.ts
@@ -74,6 +74,7 @@ declare module "preact" {
src: string;
class: string;
key?: string | number;
+ partition?: string;
}
interface IntrinsicElements {
diff --git a/apps/client/src/widgets/type_widgets/WebView.tsx b/apps/client/src/widgets/type_widgets/WebView.tsx
index 1a7e7d77db..50d689bc91 100644
--- a/apps/client/src/widgets/type_widgets/WebView.tsx
+++ b/apps/client/src/widgets/type_widgets/WebView.tsx
@@ -1,5 +1,6 @@
import "./WebView.css";
+import { WEBVIEW_SESSION_PARTITION } from "@triliumnext/commons";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import appContext from "../../components/app_context";
@@ -54,10 +55,15 @@ function DesktopWebView({ src, ntxId }: { src: string, ntxId: string | null | un
};
}, [ ntxId ]);
+ // The dedicated partition keeps remote guest pages out of the renderer's
+ // default session: separate cookie jar/storage, and no access to the
+ // trilium-app:// protocol (per-session registry), so embedded sites can
+ // neither ride the app's session cookie nor reach its origin.
return <webview
ref={webviewRef}
src={src}
key={src}
+ partition={WEBVIEW_SESSION_PARTITION}
class="note-detail-web-view-content"
/>;
}
diff --git a/packages/commons/src/lib/shared_constants.ts b/packages/commons/src/lib/shared_constants.ts
index 2e5425143d..3c6c116b57 100644
--- a/packages/commons/src/lib/shared_constants.ts
+++ b/packages/commons/src/lib/shared_constants.ts
@@ -40,3 +40,13 @@ const SHELL_OPEN_EXTERNAL_BLOCKLIST = new Set([
export const SHELL_OPEN_EXTERNAL_PROTOCOLS = ALLOWED_PROTOCOLS.filter(
p => !SHELL_OPEN_EXTERNAL_BLOCKLIST.has(p)
);
+
+// Session partition for <webview> guests (the Web View note type on desktop).
+// Remote pages must not share the default session with the trilium-app://
+// renderer: a separate partition gives them their own cookie jar, storage and
+// protocol registry, so guest content can neither ride the app's session
+// cookie nor resolve trilium-app:// URLs at all. `persist:` keeps the
+// partition on disk so logins inside web views survive app restarts.
+// Shared between the client (<webview partition=...>) and the desktop main
+// process (session.fromPartition() for permission handlers).
+export const WEBVIEW_SESSION_PARTITION = "persist:webview";