Skip to content

The agent that grows with you

fix(desktop): honor proxy env for update API checks

Jony7473088b4d84
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 3eecfd36c65..b83d2fcf02b 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -436,6 +436,7 @@ import {
rateLimitFromHeaders,
resolveBehindLocally
} from './update-api-check'
+import { updateCheckAgent } from './update-api-proxy'
import { waitForUpdateClearance } from './update-gate'
import { readLiveUpdateMarker, updateHandoffConflict, writeUpdateMarker } from './update-marker'
import { isOfficialSshRemote, OFFICIAL_REPO_HTTPS_URL } from './update-remote'
@@ -3494,6 +3495,7 @@ function fetchGitHubApiOnce(url, accept, token) {
const req = https.get(
url,
{
+ agent: updateCheckAgent(url),
headers: githubApiHeaders(
{
Accept: accept,
diff --git a/apps/desktop/electron/update-api-proxy.test.ts b/apps/desktop/electron/update-api-proxy.test.ts
new file mode 100644
index 00000000000..dbfdbb6655d
--- /dev/null
+++ b/apps/desktop/electron/update-api-proxy.test.ts
@@ -0,0 +1,86 @@
+import assert from 'node:assert/strict'
+import https from 'node:https'
+import net from 'node:net'
+
+import { afterEach, test } from 'vitest'
+
+import { updateCheckAgent } from './update-api-proxy'
+
+const keys = [
+ 'HTTPS_PROXY',
+ 'https_proxy',
+ 'HTTP_PROXY',
+ 'http_proxy',
+ 'ALL_PROXY',
+ 'all_proxy',
+ 'NO_PROXY',
+ 'no_proxy'
+] as const
+
+const saved = Object.fromEntries(keys.map(key => [key, process.env[key]]))
+
+afterEach(() => {
+ for (const key of keys) {
+ const value = saved[key]
+
+ if (value === undefined) {
+ delete process.env[key]
+ } else {
+ process.env[key] = value
+ }
+ }
+})
+
+function clearProxyEnv() {
+ for (const key of keys) {
+ delete process.env[key]
+ }
+}
+
+test('update API uses an HTTPS proxy only when the environment selects one', () => {
+ clearProxyEnv()
+ const url = 'https://api.github.com/repos/NousResearch/hermes-agent/commits/main'
+
+ assert.equal(updateCheckAgent(url), undefined)
+ process.env.HTTPS_PROXY = 'http://127.0.0.1:8080'
+ assert.ok(updateCheckAgent(url))
+ process.env.NO_PROXY = 'api.github.com'
+ assert.equal(updateCheckAgent(url), undefined)
+})
+
+test('update API request reaches the configured HTTP CONNECT proxy', async () => {
+ clearProxyEnv()
+ let connectRequest = ''
+
+ const server = net.createServer(socket => {
+ socket.once('data', data => {
+ connectRequest = data.toString()
+ socket.end('HTTP/1.1 502 Bad Gateway\r\nContent-Length: 0\r\n\r\n')
+ })
+ })
+
+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve))
+
+ try {
+ const address = server.address()
+ assert.ok(address && typeof address !== 'string')
+ process.env.HTTPS_PROXY = `http://127.0.0.1:${address.port}`
+
+ const status = await new Promise<number | undefined>((resolve, reject) => {
+ https
+ .get(
+ 'https://api.github.com/repos/NousResearch/hermes-agent/commits/main',
+ {
+ agent: updateCheckAgent('https://api.github.com/repos/NousResearch/hermes-agent/commits/main')
+ },
+ res => resolve(res.statusCode)
+ )
+ .on('error', reject)
+ })
+
+ assert.equal(status, 502)
+ assert.match(connectRequest, /^CONNECT api\.github\.com:443 HTTP\/1\.1\r\n/)
+ } finally {
+ server.close()
+ }
+})
diff --git a/apps/desktop/electron/update-api-proxy.ts b/apps/desktop/electron/update-api-proxy.ts
new file mode 100644
index 00000000000..294da7afbbe
--- /dev/null
+++ b/apps/desktop/electron/update-api-proxy.ts
@@ -0,0 +1,9 @@
+import { HttpsProxyAgent } from 'https-proxy-agent'
+import { getProxyForUrl } from 'proxy-from-env'
+
+/** Node's https.get ignores proxy env vars; resolve them only for update API requests. */
+export function updateCheckAgent(url: string): HttpsProxyAgent<string> | undefined {
+ const proxyUrl = getProxyForUrl(url)
+
+ return proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined
+}
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 792b7afb25e..cd8ec321fda 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -124,12 +124,14 @@
"frimousse": "0.3.0",
"hast-util-from-html-isomorphic": "2.0.0",
"hast-util-to-text": "4.0.2",
+ "https-proxy-agent": "^7.0.6",
"ignore": "7.0.6",
"katex": "0.16.47",
"mermaid": "11.16.1",
"motion": "12.42.2",
"nanostores": "1.4.2",
"node-pty": "1.1.0",
+ "proxy-from-env": "^2.1.0",
"qrcode": "1.5.4",
"radix-ui": "1.6.7",
"react": "19.2.7",
@@ -167,6 +169,7 @@
"@types/d3-force": "3.0.10",
"@types/hast": "3.0.5",
"@types/node": "22.20.1",
+ "@types/proxy-from-env": "^1.0.4",
"@types/qrcode": "1.5.6",
"@types/react": "19.2.17",
"@types/react-dom": "19.2.3",
diff --git a/package-lock.json b/package-lock.json
index 1f861bbdf47..381d70a0451 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -112,12 +112,14 @@
"frimousse": "0.3.0",
"hast-util-from-html-isomorphic": "2.0.0",
"hast-util-to-text": "4.0.2",
+ "https-proxy-agent": "^7.0.6",
"ignore": "7.0.6",
"katex": "0.16.47",
"mermaid": "11.16.1",
"motion": "12.42.2",
"nanostores": "1.4.2",
"node-pty": "1.1.0",
+ "proxy-from-env": "^2.1.0",
"qrcode": "1.5.4",
"radix-ui": "1.6.7",
"react": "19.2.7",
@@ -152,6 +154,7 @@
"@types/d3-force": "3.0.10",
"@types/hast": "3.0.5",
"@types/node": "22.20.1",
+ "@types/proxy-from-env": "^1.0.4",
"@types/qrcode": "1.5.6",
"@types/react": "19.2.17",
"@types/react-dom": "19.2.3",
@@ -6848,6 +6851,16 @@
"xmlbuilder": ">=11.0.1"
}
},
+ "node_modules/@types/proxy-from-env": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@types/proxy-from-env/-/proxy-from-env-1.0.4.tgz",
+ "integrity": "sha512-TPR9/bCZAr3V1eHN4G3LD3OLicdJjqX1QRXWuNcCYgE66f/K8jO2ZRtHxI2D9MbnuUP6+qiKSS8eUHp6TFHGCw==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@types/qrcode": {
"version": "1.5.6",
"resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.5.6.tgz",
@@ -7436,7 +7449,6 @@
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
"integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",
- "devOptional": true,
"license": "MIT",
"engines": {
"node": ">= 14"
@@ -12262,7 +12274,6 @@
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz",
"integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==",
- "devOptional": true,
"license": "MIT",
"dependencies": {
"agent-base": "^7.1.2",
@@ -15809,7 +15820,6 @@
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz",
"integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==",
- "dev": true,
"license": "MIT",
"engines": {
"node": ">=10"