Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(desktop): let the active remote server's page enable notifications
AdityaUmale3b1088f2d67f
diff --git a/electron/app-permissions.mjs b/electron/app-permissions.mjsindex 85ea0e30c5..9e1e4cb8da 100644--- a/electron/app-permissions.mjs+++ b/electron/app-permissions.mjs@@ -73,14 +73,16 @@ export function remoteClipboardWriteAllowed(permission, requestingUrlOrOrigin, a* homeOrigin?: () => string | null }} context* Every getter is read per request, so a sign-out or server switch withdraws access at once. `homeOrigin`: My Cloud* once the person's bots moved there (home-window.mjs), whose page alone may show notifications besides this- * computer's.+ * computer's and the active remote server's.*/export function appPermissionHandlers({ rendererOrigin, mainContents, cloudHomeOrigin, cloudHomeRestoring = () => null, activeRemoteOrigin = () => null,activeRemoteMicrophone = () => false, askRemoteMicrophone = () => null, homeOrigin = () => null }) {- const notifiesAtHome = (contents, permission, requesting, details) => {- const home = webOrigin(homeOrigin());- return permission === "notifications" && Boolean(home) && Boolean(contents) && contents === mainContents() &&- details?.isMainFrame === true && webOrigin(requesting) === home;+ // Notifications for the main window's main frame on `origin`: My Cloud as home, or the remote server the person+ // switched to (Settings → Notifications there has no browser site settings to fall back on).+ const notifiesAs = (origin, contents, permission, requesting, details) => {+ const page = webOrigin(origin);+ return permission === "notifications" && Boolean(page) && Boolean(contents) && contents === mainContents() &&+ details?.isMainFrame === true && webOrigin(requesting) === page;};const asksAsCloud = (contents, permission, requesting, details) =>Boolean(contents) && contents === mainContents() && mainFrameMicrophoneAllowed(permission, requesting, requesting, details);@@ -95,7 +97,8 @@ export function appPermissionHandlers({ rendererOrigin, mainContents, cloudHomeO(asksAsCloud(contents, permission, requesting, details) && mainFrameMicrophoneAllowed(permission, requesting, cloudHomeOrigin(), details)) ||(asksAsRemote(contents, permission, requesting, details) && activeRemoteMicrophone() === true) ||clipboardWrite(contents, permission, requesting, details) ||- notifiesAtHome(contents, permission, requesting, details);+ notifiesAs(homeOrigin(), contents, permission, requesting, details) ||+ notifiesAs(activeRemoteOrigin(), contents, permission, requesting, details);return {// Only a request may wait (Electron answers through the callback); the rule runs again after any wait.request: (contents, permission, callback, details) => {diff --git a/electron/app-permissions.node-test.mjs b/electron/app-permissions.node-test.mjsindex d9a1f7eb8d..a7a61e2be3 100644--- a/electron/app-permissions.node-test.mjs+++ b/electron/app-permissions.node-test.mjs@@ -525,3 +525,25 @@ test("the base policy itself still grants a remote origin nothing", () => {assert.equal(appPermissionAllowed(permission, REMOTE, LOCAL_ORIGIN, { isMainFrame: true }), false, permission);}});++test("the active remote server's page may show notifications, in the main window's main frame only", () => {+ const state = { remote: REMOTE, main: { getURL: () => `${REMOTE}/chat` } };+ const handlers = appPermissionHandlers({ rendererOrigin: () => LOCAL_ORIGIN, mainContents: () => state.main, cloudHomeOrigin: () => null,+ activeRemoteOrigin: () => state.remote });+ const onRemote = (extra = {}) => ({ requestingUrl: `${REMOTE}/settings`, isMainFrame: true, ...extra });+ const ask = (details, contents = state.main, permission = "notifications") => {+ let granted; handlers.request(contents, permission, (value) => { granted = value; }, details); return granted;+ };+ assert.equal(ask(onRemote()), true);+ assert.equal(handlers.check(state.main, "notifications", REMOTE, { isMainFrame: true }), true);+ assert.equal(ask(onRemote({ isMainFrame: false })), false, "a frame inside it");+ assert.equal(handlers.check(state.main, "notifications", REMOTE, {}), false, "a frame it cannot vouch for");+ assert.equal(ask(onRemote(), { getURL: () => `${REMOTE}/` }), false, "another window");+ assert.equal(ask(onRemote({ requestingUrl: "https://other.tail1.ts.net:9444/" })), false, "another server");+ for (const permission of ["geolocation", "camera", "clipboard-read", "fullscreen"]) {+ assert.equal(ask(onRemote(), state.main, permission), false, permission);+ }+ state.remote = null;+ assert.equal(ask(onRemote()), false, "no active remote: at once");+ for (const requesting of ["about:blank", "data:text/html,x", ""]) assert.equal(ask(onRemote({ requestingUrl: requesting })), false, `${requesting || "(empty)"}`);+});diff --git a/electron/remote-clipboard-permission.node-test.mjs b/electron/remote-clipboard-permission.node-test.mjsindex dc9e79f89c..d7e4522d32 100644--- a/electron/remote-clipboard-permission.node-test.mjs+++ b/electron/remote-clipboard-permission.node-test.mjs@@ -50,9 +50,10 @@ test("the active paired server may write the clipboard, on request and on check"assert.equal(h.check("clipboard-sanitized-write", "", { isMainFrame: true }, Object.assign(h.mainContents, { getURL: () => `${VPS}/chat` })), true);});+// Notifications are the one other permission the active server's main frame gets (app-permissions.node-test.mjs).test("a remote page can never read the clipboard or gain another permission", () => {const h = harness(viewing("vps"));- for (const permission of ["clipboard-read", "notifications", "fullscreen", "media", "geolocation", "camera", "display-capture", "openExternal", "unknown"]) {+ for (const permission of ["clipboard-read", "fullscreen", "media", "geolocation", "camera", "display-capture", "openExternal", "unknown"]) {assert.equal(h.request(permission, `${VPS}/`, { isMainFrame: true, mediaTypes: ["audio"] }), false, `request ${permission}`);assert.equal(h.check(permission, VPS), false, `check ${permission}`);}