Skip to content

The agent that grows with you

fix(desktop): validate the configured App Installer feed base and refuse descriptor redirects

ethernetfaffafa4ddec
diff --git a/apps/desktop/electron/app-installer-file.test.ts b/apps/desktop/electron/app-installer-file.test.ts
index dc103cb6250..fce7d42bf4e 100644
--- a/apps/desktop/electron/app-installer-file.test.ts
+++ b/apps/desktop/electron/app-installer-file.test.ts
@@ -10,10 +10,13 @@ import { stageAppInstallerFile } from './app-installer-file'
test('stages an actual HTTP descriptor and leaves a valid file intact on download failure', async () => {
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'hermes-installer-file-'))
const descriptor = '<?xml version="1.0"?><AppInstaller Uri="https://updates.example/app.appinstaller" />'
+ let base = ''
const server = http.createServer((request, response) => {
if (request.url === '/missing') {
response.writeHead(404).end()
+ } else if (request.url === '/redirect') {
+ response.writeHead(302, { location: `${base}/update` }).end()
} else if (request.url === '/large') {
response.end(Buffer.alloc(1024 * 1024 + 1))
} else {
@@ -28,7 +31,7 @@ test('stages an actual HTTP descriptor and leaves a valid file intact on downloa
throw new Error('missing server address')
}
- const base = `http://127.0.0.1:${address.port}`
+ base = `http://127.0.0.1:${address.port}`
try {
const target = await stageAppInstallerFile(`${base}/update`, directory)
@@ -36,6 +39,8 @@ test('stages an actual HTTP descriptor and leaves a valid file intact on downloa
expect(await fs.readFile(target, 'utf8')).toBe(descriptor)
await expect(stageAppInstallerFile(`${base}/missing`, directory)).rejects.toThrow('404')
await expect(stageAppInstallerFile(`${base}/large`, directory)).rejects.toThrow('1 MiB')
+ // A redirect off the validated feed origin is refused, even back onto it.
+ await expect(stageAppInstallerFile(`${base}/redirect`, directory)).rejects.toThrow()
expect(await fs.readFile(target, 'utf8')).toBe(descriptor)
expect(await fs.readdir(directory)).toEqual(['update.appinstaller'])
} finally {
diff --git a/apps/desktop/electron/app-installer-file.ts b/apps/desktop/electron/app-installer-file.ts
index 2b6eb8af201..20bf70a061c 100644
--- a/apps/desktop/electron/app-installer-file.ts
+++ b/apps/desktop/electron/app-installer-file.ts
@@ -7,7 +7,10 @@ export async function stageAppInstallerFile(
directory: string,
fetchFile: typeof fetch = fetch
): Promise<string> {
- const response = await fetchFile(url, { signal: AbortSignal.timeout(30_000) })
+ // No redirects: the descriptor must come from the validated feed origin
+ // itself, not from wherever that origin's operator (or a hijacked hop)
+ // points next. Windows verifies the referenced package, not this file.
+ const response = await fetchFile(url, { signal: AbortSignal.timeout(30_000), redirect: 'error' })
if (!response.ok || !response.body) {
throw new Error(`App Installer descriptor download failed: HTTP ${response.status}`)
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 8d760499d3d..9e43951c762 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -486,7 +486,7 @@ import { verifyPreparedChannelInstaller } from './updater/channel-windows-host'
import { createCheckoutStrategy } from './updater/checkout'
import { readSourceUpdate, type SourceUpdate } from './updater/checkout-source'
import { ExternalStrategy } from './updater/external'
-import { readUpdatesFeedBaseFromConfig } from './updater/feed-config'
+import { readUpdatesFeedBaseFromConfig, resolveFeedBaseUrl } from './updater/feed-config'
import { createChannelMacStrategy, createMacStrategy } from './updater/mac-client'
import { UpdateOperation } from './updater/operation'
import {
@@ -3303,19 +3303,10 @@ function resolveCheckoutUpdateStrategy(): UpdaterStrategy {
* Windows' registered App Installer source when no override is set.
*/
function resolveDesktopFeedBaseUrl(): string {
- const configured: string = readUpdatesFeedBaseFromConfig(path.join(HERMES_HOME, 'config.yaml'))
-
- if (configured) {
- return configured
- }
-
- const env: string | undefined = process.env.HERMES_DESKTOP_FEED_BASE_URL
-
- if (env) {
- return env
- }
-
- return ''
+ return resolveFeedBaseUrl(
+ readUpdatesFeedBaseFromConfig(path.join(HERMES_HOME, 'config.yaml')),
+ process.env.HERMES_DESKTOP_FEED_BASE_URL
+ )
}
/** The updater channel from the baked install stamp ('canary' vs 'stable'). */
diff --git a/apps/desktop/electron/updater/feed-config.test.ts b/apps/desktop/electron/updater/feed-config.test.ts
index 0fa4939e044..689958e7318 100644
--- a/apps/desktop/electron/updater/feed-config.test.ts
+++ b/apps/desktop/electron/updater/feed-config.test.ts
@@ -4,7 +4,7 @@ import { join } from 'node:path'
import { expect, it } from 'vitest'
-import { readUpdatesFeedBaseFromConfig } from './feed-config'
+import { readUpdatesFeedBaseFromConfig, resolveFeedBaseUrl } from './feed-config'
it('reads only the updates feed across equivalent YAML representations', (): void => {
const home: string = mkdtempSync(join(tmpdir(), 'hermes-feed-config-'))
@@ -56,3 +56,19 @@ it('leaves fallback selection available for missing, invalid or non-string confi
rmSync(home, { recursive: true, force: true })
}
})
+
+
+it('holds a configured or env feed base to the update-origin rule and refuses the rest', (): void => {
+ expect(resolveFeedBaseUrl('', undefined)).toBe('')
+ expect(resolveFeedBaseUrl('', ' ')).toBe('')
+ expect(resolveFeedBaseUrl('https://mirror.example/updates', 'http://evil.example/feed')).toBe(
+ 'https://mirror.example/updates'
+ )
+ expect(resolveFeedBaseUrl('', 'https://mirror.example/updates')).toBe('https://mirror.example/updates')
+ expect(resolveFeedBaseUrl('', 'http://127.0.0.1:8443/feed')).toBe('http://127.0.0.1:8443/feed')
+
+ for (const bad of ['http://evil.example/feed', 'https://user:[email protected]/feed', 'https://mirror.example/../feed']) {
+ expect((): string => resolveFeedBaseUrl(bad, undefined)).toThrow()
+ expect((): string => resolveFeedBaseUrl('', bad)).toThrow()
+ }
+})
diff --git a/apps/desktop/electron/updater/feed-config.ts b/apps/desktop/electron/updater/feed-config.ts
index 9f5ea2e0c12..be1a74743b2 100644
--- a/apps/desktop/electron/updater/feed-config.ts
+++ b/apps/desktop/electron/updater/feed-config.ts
@@ -2,6 +2,30 @@ import { readFileSync } from 'node:fs'
import { load } from 'js-yaml'
+import { channelPublicBase } from './channel-protocol'
+
+/**
+ * The feed base a bundled install downloads its update descriptor from:
+ * config.yaml's `updates.desktop_feed_base_url`, then the env override,
+ * else '' (the OS-registered App Installer source / no feed). A configured
+ * value is held to the same rule as every other update origin
+ * (channelPublicBase: HTTPS or loopback, no credentials/traversal) — the
+ * descriptor is fetched and opened unverified, so a plain-http base would
+ * hand a network attacker the update source. Throws on a bad value rather
+ * than silently falling back, so the misconfiguration is named.
+ */
+export function resolveFeedBaseUrl(configured: string, envOverride: string | undefined): string {
+ const value: string = configured || (envOverride ?? '').trim()
+
+ if (!value) {
+ return ''
+ }
+
+ channelPublicBase(value)
+
+ return value
+}
+
export function readUpdatesFeedBaseFromConfig(configPath: string): string {
try {
// YAML permits scalar and sequence roots; validate the nested string at this I/O boundary.