Review round on the system-proxy hand-off (#123387): - The resolved proxy leaked into the relaunched Desktop and everything it starts. posix.sh relaunched with the update env scrubbed but the proxy env kept, the Windows Start-Process rung and the staged updater pass their env on, and gateways `hermes update` restarts inherit it. With a NO_PROXY of only localhost, every LAN or internal host the PAC sends direct went through the proxy, and the next update read the stale proxy as an explicit user setting and never re-resolved it. The Desktop now names each variable it adds in HERMES_UPDATE_SYSTEM_PROXY and saves a NO_PROXY of the user's it extends as HERMES_UPDATE_USER_<KEY>. The Desktop restores its own env at entry (every relaunch rung), posix.sh restores it in the relaunch subshells (Linux and macOS), windows.ps1 before the tethered Start-Process rung, and the gateway and serve/dashboard at start. A marked value is never taken for the user's own on the next update. - NO_PROXY gains 127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 and .local, and a user NO_PROXY is extended instead of replaced. The user's value previously also overrode the extended one, because process.env was spread after the proxy env. - Each update host is resolved on its own, and the env proxy is exported only when every host is either that one plain PROXY or DIRECT. A PAC that sends hosts to different proxies gets a logged note and no env. - SOCKS and HTTPS answers are no longer exported. Chromium's "SOCKS" is SOCKS4 and was mapped to socks5h. Beyond that, Python's urllib sends a plaintext CONNECT to any proxy URL, npm reads no SOCKS env, httpx refuses socks4, and the update's own git calls drop injected git config. They get a logged note instead. Live (Electron 44.9.3 on Xvnc :95): - Before: the built Desktop launched with a marked proxy env gave its Python backend all six proxy variables. After: only the user's NO_PROXY=corp.internal. - The real posix.sh --relaunch-target: `hermes update` still gets the proxy, and the relaunched app gets none (before: all six). - A PAC resolving LAN and corp hosts DIRECT keeps them direct, and so do the update's localhost calls.
96 lines
3.4 KiB
TypeScript
96 lines
3.4 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
|
|
import { app } from 'electron'
|
|
|
|
import { resolveDesktopHermesHome } from './data-paths'
|
|
import { releasePackagedWorkingDirectory } from './packaged-working-directory'
|
|
import { readDesktopLaunchConfig } from './renderer-heap-flags'
|
|
import { restoreUserProxyEnv } from './updater/system-proxy-env'
|
|
import { wslgLaunchArgs } from './wslg-launch'
|
|
import { spawnWslgLaunch } from './wslg-launch-process'
|
|
|
|
// A Desktop relaunched by an update (any rung: hand-off script, staged updater,
|
|
// Start-Process) must not keep the system proxy the update's children were given.
|
|
restoreUserProxyEnv(process.env)
|
|
|
|
// `hermes desktop` asks this binary whether Chromium's namespace sandbox starts under the host's
|
|
// AppArmor policy (#130177). Chromium creates its sandboxed zygote before any JS runs, so reaching
|
|
// this line answers yes; exit before any window, single-instance lock, backend or relaunch.
|
|
if (process.argv.includes('--hermes-sandbox-probe')) {
|
|
process.exit(0)
|
|
}
|
|
|
|
// Run before main creates windows/IME integrations or spawns resident helpers.
|
|
// Closing Hermes cannot release a CWD inherited by an out-of-tree process.
|
|
releasePackagedWorkingDirectory(app.isPackaged || Boolean(process.env.HERMES_DESKTOP_IS_PACKAGED))
|
|
|
|
function configuredElectronFlags(env: NodeJS.ProcessEnv): string[] {
|
|
// Resolve the home exactly like main.ts does, through the shared resolver:
|
|
// HERMES_DATA_DIR_SUFFIX channel installs and profiles/-rooted HERMES_HOME
|
|
// values must pick the same config.yaml before the relaunch and inside the
|
|
// app, or desktop.electron_flags silently never reaches the relaunch.
|
|
const home = resolveDesktopHermesHome({
|
|
home: os.homedir(),
|
|
env,
|
|
// Linux-only pre-launch path; the win32 legacy-migration probe is never
|
|
// consulted on posix, so its directoryExists callback is not needed here.
|
|
directoryExists: () => false,
|
|
readWindowsHome: () => null
|
|
})
|
|
|
|
try {
|
|
return readDesktopLaunchConfig(readFileSync(path.join(home, 'config.yaml'), 'utf8')).electronFlags
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
const linux = process.platform === 'linux'
|
|
const electronFlags = linux ? configuredElectronFlags(process.env) : []
|
|
|
|
// True only when the NVIDIA proprietary kernel module is loaded
|
|
// (not nouveau, not the open kernel module, not WSL's dxg passthrough).
|
|
function hasNvidiaProprietaryDriver() {
|
|
if (process.platform !== 'linux') {
|
|
return false
|
|
}
|
|
|
|
try {
|
|
const version = readFileSync('/proc/driver/nvidia/version', 'utf8') || ''
|
|
|
|
return !/Open Kernel Module/.test(version)
|
|
} catch {
|
|
return false // no nvidia driver on this box
|
|
}
|
|
}
|
|
|
|
const args = wslgLaunchArgs(
|
|
process.argv.slice(1),
|
|
process.env,
|
|
process.platform,
|
|
electronFlags,
|
|
hasNvidiaProprietaryDriver()
|
|
)
|
|
|
|
if (args) {
|
|
// Keep the launcher alive until the child exits: npm's concurrently must not
|
|
// tear down Vite during this handoff. No backend, windows or single-instance
|
|
// lock are created in this parent. The child has an explicit platform flag,
|
|
// so it goes straight into main on its first pass.
|
|
const child = spawnWslgLaunch(args)
|
|
|
|
child.once('error', error => {
|
|
console.error('[hermes] Wayland ozone launch failed:', error)
|
|
app.exit(1)
|
|
})
|
|
child.once('exit', code => app.exit(code ?? 1))
|
|
|
|
for (const signal of ['SIGINT', 'SIGTERM'] as const) {
|
|
process.once(signal, () => child.kill(signal))
|
|
}
|
|
} else {
|
|
await import('./main')
|
|
}
|