The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): native plugin install clones https only and refuses symlinked desktop trees
Teknium9d4ab00f33b5
diff --git a/apps/desktop/electron/desktop-plugin-install.test.ts b/apps/desktop/electron/desktop-plugin-install.test.tsindex d5dd660dcab..892fd306c67 100644--- a/apps/desktop/electron/desktop-plugin-install.test.ts+++ b/apps/desktop/electron/desktop-plugin-install.test.ts@@ -288,6 +288,35 @@ describe('installDesktopPluginFromGit', () => {expect(fs.readFileSync(path.join(appRoot, result.pluginName!, 'panel.js'), 'utf8')).toBe('reviewed\n')})+ it.each([+ ['a symlinked file inside it', (repo: string) => fs.symlinkSync('/etc/hostname', path.join(repo, 'desktop', 'leak.txt'))],+ [+ 'a symlinked desktop folder',+ (repo: string, outside: string) => {+ fs.renameSync(path.join(repo, 'desktop'), path.join(outside, 'desktop'))+ fs.symlinkSync(path.join(outside, 'desktop'), path.join(repo, 'desktop'))+ }+ ]+ ])('refuses a desktop tree with %s and publishes nothing', async (_label, link) => {+ // A symlink in the copied tree would publish whatever it points at on this machine as plugin files.+ const repo = pluginRepo(null)+ const outside = mkdtemp('hermes-plugin-outside-')+ const appRoot = mkdtemp('hermes-plugin-root-')+ roots.push(outside, appRoot)+ link(repo, outside)+ execFileSync('git', ['add', '-A'], { cwd: repo, stdio: 'pipe' })+ execFileSync('git', ['-c', '[email protected]', '-c', 'user.name=F', 'commit', '-qm', 'link'], {+ cwd: repo,+ stdio: 'pipe'+ })++ const result = await installDesktopPluginFromGit('git', pathToFileURL(repo).href, appRoot)++ expect(result.ok).toBe(false)+ expect(result.error).toContain('symbolic link')+ expect(fs.readdirSync(appRoot)).toEqual([])+ })+it('stamps the package marker on a unified package half and names the folder after the agent package', async () => {// Without the marker the Plugins page has no evidence that this copy is the// agent row's desktop half: the row sits on "copying…" while the copy showsdiff --git a/apps/desktop/electron/desktop-plugin-install.ts b/apps/desktop/electron/desktop-plugin-install.tsindex 01fe28b0f3d..f897f90f34e 100644--- a/apps/desktop/electron/desktop-plugin-install.ts+++ b/apps/desktop/electron/desktop-plugin-install.ts@@ -435,6 +435,64 @@ async function resolvePluginRoot(cloneRoot: string, subdir: string | null): Promreturn resolved}+/** Why a click in the app may not install *identifier*, else null. The app clones over https:// only:+ * `file://` copies any local folder, `ssh://`/`git@` signs in with the user's ssh-agent and `http://` is+ * unauthenticated. `hermes plugins install` in a terminal keeps every scheme it documents. */+export function guiInstallSourceRefusal(identifier: string): null | string {+ let gitUrl: string++ try {+ gitUrl = resolvePluginGitUrl(identifier).gitUrl+ } catch {+ return null // not a source at all: the installer's own error names it+ }++ if (gitUrl.startsWith('https://')) {+ return null+ }++ return 'Plugins are installed from Hermes Desktop over https:// only. Use `hermes plugins install` in a terminal for other sources.'+}++// The same cap the Webapp's host-side desktop install applies to the copied tree.+const DESKTOP_TREE_MAX_BYTES = 64 * 1024 * 1024++/** Refuse a desktop tree that reaches outside the clone or is too big to copy. A symlink anywhere on the+ * way to it, or inside it, would publish whatever it points at on this machine (or a dangling link into+ * the deleted clone) as part of the plugin, so the tree must be plain files and folders. */+async function assertPlainDesktopTree(cloneRoot: string, sourceDir: string): Promise<void> {+ const realRoot = await fsp.realpath(cloneRoot)++ if ((await fsp.realpath(sourceDir)) !== path.join(realRoot, path.relative(cloneRoot, sourceDir))) {+ throw new Error('The desktop plugin folder is a symbolic link; it is not installed.')+ }++ let total = 0+ const pending = [sourceDir]++ while (pending.length > 0) {+ const dir = pending.pop()!++ for (const entry of await fsp.readdir(dir, { withFileTypes: true })) {+ const full = path.join(dir, entry.name)++ if (entry.isSymbolicLink()) {+ throw new Error(`The desktop plugin contains a symbolic link (${path.relative(sourceDir, full)}); it is not installed.`)+ }++ if (entry.isDirectory()) {+ pending.push(full)+ } else {+ total += (await fsp.lstat(full)).size++ if (total > DESKTOP_TREE_MAX_BYTES) {+ throw new Error(`The desktop plugin is larger than ${DESKTOP_TREE_MAX_BYTES / (1024 * 1024)} MB.`)+ }+ }+ }+ }+}+function insecureSchemeWarnings(gitUrl: string): { warnings: string[]; insecure: boolean } {if (gitUrl.startsWith('http://') || gitUrl.startsWith('file://')) {return {@@ -521,6 +579,8 @@ export async function installDesktopPluginFromGit(const sourceDir =detected.desktopSourceSubdir === '.' ? pluginRoot : path.join(pluginRoot, detected.desktopSourceSubdir)+ await assertPlainDesktopTree(cloneRoot, sourceDir)+// A repo carrying BOTH halves is one package: land its desktop half under// the AGENT package name, so the copy this app makes and the one// `reconcileUnifiedDesktopHalves` would make are the same folder (#100412)diff --git a/apps/desktop/electron/fs-ipc.test.ts b/apps/desktop/electron/fs-ipc.test.tsindex b7ce849154d..a9b9b8fc7a5 100644--- a/apps/desktop/electron/fs-ipc.test.ts+++ b/apps/desktop/electron/fs-ipc.test.ts@@ -10,6 +10,8 @@ import path from 'node:path'import { afterEach, describe, expect, it, vi } from 'vitest'+import type * as DesktopPluginInstall from './desktop-plugin-install'+const electron = vi.hoisted(() => ({handlers: new Map<string, (...args: unknown[]) => unknown>(),showItemInFolder: vi.fn()@@ -28,7 +30,11 @@ vi.mock('electron', () => ({}}))-vi.mock('./desktop-plugin-install', () => ({ installDesktopPluginFromGit: vi.fn(), probePluginRepo: vi.fn() }))+vi.mock('./desktop-plugin-install', async importOriginal => ({+ guiInstallSourceRefusal: (await importOriginal<typeof DesktopPluginInstall>()).guiInstallSourceRefusal,+ installDesktopPluginFromGit: vi.fn(async () => ({ ok: true })),+ probePluginRepo: vi.fn()+}))vi.mock('./desktop-plugins-root', () => ({DESKTOP_PLUGINS_DIR: 'desktop-plugins',ensureDir: vi.fn(async (dir: string) => dir),@@ -36,6 +42,7 @@ vi.mock('./desktop-plugins-root', () => ({reconcileUnifiedDesktopHalves: vi.fn()}))+import { installDesktopPluginFromGit } from './desktop-plugin-install'import { registerFsIpc } from './fs-ipc'const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-fs-ipc-'))@@ -111,3 +118,31 @@ describe('hermes:fs:logsRoot', () => {}})})++// A click in the app clones over https:// only; `hermes plugins install` keeps the other schemes.+describe('hermes:plugin:installDesktop', () => {+ const install = (identifier: string) =>+ electron.handlers.get('hermes:plugin:installDesktop')!({}, { identifier }) as Promise<{ error?: string; ok: boolean }>++ it.each([+ 'file:///srv/plugin',+ 'ssh://[email protected]/acme/plugin.git',+ '[email protected]:acme/plugin.git',+ 'http://example.com/acme/plugin.git'+ ])('refuses %s before any clone', async identifier => {+ vi.mocked(installDesktopPluginFromGit).mockClear()++ const result = await install(identifier)++ expect(result.ok).toBe(false)+ expect(result.error).toContain('https://')+ expect(installDesktopPluginFromGit).not.toHaveBeenCalled()+ })++ it.each(['https://example.com/acme/plugin.git', 'acme/plugin'])('installs %s', async identifier => {+ vi.mocked(installDesktopPluginFromGit).mockClear()++ await expect(install(identifier)).resolves.toMatchObject({ ok: true })+ expect(installDesktopPluginFromGit).toHaveBeenCalledOnce()+ })+})diff --git a/apps/desktop/electron/fs-ipc.ts b/apps/desktop/electron/fs-ipc.tsindex 666a7801da9..f31530591ee 100644--- a/apps/desktop/electron/fs-ipc.ts+++ b/apps/desktop/electron/fs-ipc.ts@@ -9,7 +9,7 @@ import path from 'node:path'import { app, BrowserWindow, dialog, ipcMain, shell } from 'electron'import { platformDefaultHermesHome } from './data-paths'-import { installDesktopPluginFromGit, probePluginRepo } from './desktop-plugin-install'+import { guiInstallSourceRefusal, installDesktopPluginFromGit, probePluginRepo } from './desktop-plugin-install'import { removeDesktopPlugin } from './desktop-plugin-remove'import {DESKTOP_PLUGINS_DIR,@@ -187,6 +187,12 @@ export function registerFsIpc({return { ok: false, error: 'identifier is required' }}+ const refusal = guiInstallSourceRefusal(identifier)++ if (refusal) {+ return { ok: false, error: refusal }+ }+return installDesktopPluginFromGit(resolveGitBinary(),identifier,