Skip to content

The agent that grows with you

fix(deps): bump simple-git 3.36.0 → 4.0.2 (critical, GHSA-x6jw-m9v5-85vh)

Maciej Lisiewski14f2ca2bf40f
diff --git a/apps/desktop/electron/git-review-ops.test.ts b/apps/desktop/electron/git-review-ops.test.ts
index f4f765b73ff..abe352d7225 100644
--- a/apps/desktop/electron/git-review-ops.test.ts
+++ b/apps/desktop/electron/git-review-ops.test.ts
@@ -4,7 +4,6 @@ import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
-import simpleGit from 'simple-git'
import { afterEach, test, vi } from 'vitest'
import {
@@ -14,7 +13,7 @@ import {
REVIEW_FILE_CAP,
reviewCreatePr,
reviewList,
- SIMPLE_GIT_UNSAFE_BINARY_WARN
+ simpleGitHostEnv
} from './git-review-ops'
import type * as NoConsoleGit from './no-console-git'
@@ -97,38 +96,139 @@ test('gitFor accepts a Windows no-console host tuple with restricted characters'
}
})
-test('gitFor suppresses only the known custom-binary warning and restores console.warn', () => {
- const spacedBin = String.raw`C:\Program Files\Git\cmd\git.exe`
- // `windowsGitHost()` resolves nothing in this process (no configured roots, no
- // HERMES_DESKTOP_PYTHON), so `gitBin` itself is what simple-git validates — the
- // spaced `Program Files` path, which warns once per factory call.
- const warnings: unknown[][] = []
- const originalWarn = console.warn
+test('simpleGitHostEnv forwards the allow-listed git variables and drops the other guarded ones', () => {
+ const env = simpleGitHostEnv(
+ {
+ PATH: '/bin',
+ HOME: '/home/u',
+ GIT_SSH_COMMAND: 'ssh -i key',
+ GIT_SSH: '/usr/bin/ssh',
+ GIT_ASKPASS: '/usr/bin/askpass',
+ SSH_ASKPASS: '/usr/bin/ssh-askpass',
+ GIT_TERMINAL_PROMPT: '1',
+ GIT_PAGER: 'cat',
+ GIT_DIR: '/elsewhere/.git',
+ git_work_tree: '/elsewhere',
+ GIT_CONFIG_GLOBAL: '/tmp/gitconfig',
+ EDITOR: 'vim',
+ VISUAL: 'code',
+ PAGER: 'less',
+ PREFIX: '/usr'
+ },
+ 'git'
+ )
- const recordingWarn = (...args: unknown[]) => {
- warnings.push(args)
- }
+ assert.deepEqual(env, {
+ PATH: '/bin',
+ HOME: '/home/u',
+ GIT_SSH_COMMAND: 'ssh -i key',
+ GIT_SSH: '/usr/bin/ssh',
+ GIT_ASKPASS: '/usr/bin/askpass',
+ SSH_ASKPASS: '/usr/bin/ssh-askpass',
+ GIT_TERMINAL_PROMPT: '1',
+ HERMES_GIT_ARGV0: '"git"'
+ })
+})
- console.warn = recordingWarn
+test('simpleGitHostEnv still defaults GIT_TERMINAL_PROMPT off for the host tuple', () => {
+ assert.equal(simpleGitHostEnv({ PATH: '/bin' }, 'git').GIT_TERMINAL_PROMPT, '0')
+})
- try {
- for (let i = 0; i < 5; i += 1) {
- gitFor(process.cwd(), spacedBin)
- }
+// An ssh:// remote whose transport is a script recording that git ran it, so a
+// test can tell whether the user's GIT_SSH_COMMAND reached the git process.
+function makeRepoWithSshRemote() {
+ const dir = makeRepo()
+ const toolDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-fake-ssh-'))
+ const marker = path.join(toolDir, 'ssh-command-ran')
+ const sshScript = path.join(toolDir, 'fake-ssh.sh')
- assert.equal(console.warn, recordingWarn)
+ tempDirs.push(toolDir)
- // The escape hatch used directly still warns: the message gitFor filters is a
- // live emission of the installed simple-git, so the filter cannot go stale
- // silently (an upgrade that rewords it fails this test, not production).
- simpleGit({ baseDir: process.cwd(), binary: spacedBin, unsafe: { allowUnsafeCustomBinary: true } })
- console.warn('unrelated warning')
- } finally {
- console.warn = originalWarn
+ execFileSync('git', ['remote', 'add', 'origin', 'ssh://[email protected]/repo.git'], { cwd: dir })
+ fs.writeFileSync(sshScript, `#!/bin/sh\necho "$@" > "${marker}"\nexit 1\n`, { mode: 0o755 })
+
+ return { dir, marker, sshScript }
+}
+
+// Guarded variables a user's shell commonly carries; simple-git 4 rejects an
+// explicit env holding any of them and strips them when inherited.
+function stubUserGitEnv(sshScript: string) {
+ vi.stubEnv('GIT_SSH_COMMAND', sshScript)
+ vi.stubEnv('GIT_PAGER', 'cat')
+ vi.stubEnv('GIT_DIR', '/nonexistent/.git')
+ vi.stubEnv('EDITOR', 'vi')
+}
+
+test.skipIf(process.platform === 'win32')(
+ "gitFor runs git with the user's GIT_SSH_COMMAND while other inherited git variables are dropped",
+ async () => {
+ const { dir, marker, sshScript } = makeRepoWithSshRemote()
+
+ stubUserGitEnv(sshScript)
+
+ try {
+ // ls-remote fails (the fake transport exits 1); what matters is that git
+ // ran the configured ssh command, and that the inherited GIT_DIR did not
+ // point it away from the repository.
+ await assert.rejects(gitFor(dir, 'git').raw(['ls-remote', 'origin']), /Could not read from remote repository/)
+ assert.ok(fs.existsSync(marker), 'GIT_SSH_COMMAND did not reach git')
+ } finally {
+ vi.unstubAllEnvs()
+ }
}
+)
- assert.deepEqual(warnings, [[SIMPLE_GIT_UNSAFE_BINARY_WARN], ['unrelated warning']])
-})
+const HOST_PYTHON =
+ process.env.HERMES_PYTHON || process.env.UV_PYTHON || (process.platform === 'win32' ? 'python' : 'python3')
+
+test.skipIf(process.platform === 'win32')(
+ "gitFor's Windows host-tuple path forwards GIT_SSH_COMMAND and does not throw on inherited guarded variables",
+ async () => {
+ // The host tuple is the only path that hands simple-git an explicit env,
+ // which simple-git 4 rejects when it carries a guarded key. Drive it for real
+ // with the python host script.
+ execFileSync(HOST_PYTHON, ['--version'], { stdio: 'ignore' })
+
+ const { dir, marker, sshScript } = makeRepoWithSshRemote()
+ const actualNoConsole = await vi.importActual<typeof NoConsoleGit>('./no-console-git')
+ const scriptDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-git-host-'))
+
+ tempDirs.push(scriptDir)
+
+ const scriptPath = actualNoConsole.ensureNoConsoleGitScript(scriptDir)
+
+ vi.resetModules()
+ vi.doMock('./no-console-git', async importOriginal => ({
+ ...(await importOriginal<typeof NoConsoleGit>()),
+ windowsGitHost: () => ({ isWindows: true, pythonBin: HOST_PYTHON, scriptPath })
+ }))
+ stubUserGitEnv(sshScript)
+
+ try {
+ const { gitFor: gitForWithHostTuple, repoStatus: repoStatusWithHostTuple } = await import('./git-review-ops')
+
+ fs.writeFileSync(path.join(dir, 'tracked.txt'), 'changed\n')
+
+ const status = await repoStatusWithHostTuple(dir, 'git')
+
+ assert.ok(status)
+ assert.deepEqual(
+ status.files.map(file => file.path),
+ ['tracked.txt']
+ )
+
+ await assert.rejects(
+ gitForWithHostTuple(dir, 'git').raw(['ls-remote', 'origin']),
+ /Could not read from remote repository/
+ )
+ assert.ok(fs.existsSync(marker), 'GIT_SSH_COMMAND did not reach git through the host tuple')
+ } finally {
+ vi.unstubAllEnvs()
+ vi.doUnmock('./no-console-git')
+ vi.resetModules()
+ }
+ }
+)
test('resolveRenamePath: simple rename resolves to the new path', () => {
assert.equal(resolveRenamePath('old.ts => new.ts'), 'new.ts')
diff --git a/apps/desktop/electron/git-review-ops.ts b/apps/desktop/electron/git-review-ops.ts
index af9fcf8b4d7..66b95a0d5ce 100644
--- a/apps/desktop/electron/git-review-ops.ts
+++ b/apps/desktop/electron/git-review-ops.ts
@@ -8,7 +8,8 @@ import { execFile } from 'node:child_process'
import fs from 'node:fs/promises'
import path from 'node:path'
-import simpleGit from 'simple-git'
+import { isGitEnvKey } from '@simple-git/argv-parser'
+import { simpleGit } from 'simple-git'
import { resolveRequestedPathForIpc } from './hardening'
import { execGit, noConsoleGitEnv, simpleGitBinary, windowsGitHost } from './no-console-git'
@@ -19,16 +20,52 @@ const REVIEW_FILE_CAP = 2_000
const UNTRACKED_LINE_COUNT_CONCURRENCY = 16
const UNTRACKED_LINE_COUNT_MAX_BYTES = 1024 * 1024
-// simple-git 3.x validates a custom binary path against an ASCII whitelist —
-// `isBadArgument` in node_modules/simple-git/dist/cjs/index.js accepts only
-// `/^([a-z]:)?([a-z0-9/.\_~-]+)$/i`. Everything outside it is "restricted": a
+// simple-git validates a custom binary path against an ASCII whitelist
+// (`/^([a-z]:)?([a-z0-9/.\_~-]+)$/i`). Everything outside it is "restricted": a
// space in the default `C:\Program Files\Git\...`, the parentheses in
// `Program Files (x86)`, the accented user name in `C:\Users\João\...`. Without
-// the escape hatch simple-git THROWS on such a path; with it, it console.warns
-// this exact message — the flag only downgrades the throw. Exported so gitFor
-// and its tests share one source of truth.
-export const SIMPLE_GIT_UNSAFE_BINARY_WARN =
- 'Invalid value supplied for custom binary, restricted characters must be removed or supply the unsafe.allowUnsafeCustomBinary option'
+// `unsafe.allowUnsafeCustomBinary` simple-git THROWS on such a path.
+
+// simple-git 4 strips every guarded variable (any `GIT_*`, plus EDITOR, VISUAL,
+// PAGER, PREFIX, SSH_ASKPASS) from the environment git runs with, and rejects
+// the task when one is passed explicitly through `.env()`. These are the ones
+// the Review pane keeps forwarding from the user's own environment: the SSH
+// transport and askpass helpers `git push` authenticates with, and
+// GIT_TERMINAL_PROMPT, which stops a credential prompt from blocking a git
+// process that has no terminal.
+export const SIMPLE_GIT_ALLOWED_ENV = ['GIT_SSH_COMMAND', 'GIT_SSH', 'GIT_ASKPASS', 'SSH_ASKPASS', 'GIT_TERMINAL_PROMPT']
+
+// simple-git's vulnerability check additionally rejects GIT_SSH/GIT_SSH_COMMAND
+// and GIT_ASKPASS/SSH_ASKPASS in an explicit `.env()` (the Windows host path
+// below) unless these categories are enabled. The values come from the user's
+// environment, never from the renderer.
+const SIMPLE_GIT_ALLOWED_ENV_UNSAFE = { allowUnsafeAskPass: true, allowUnsafeSshCommand: true }
+
+const ALLOWED_ENV_KEYS = new Set(SIMPLE_GIT_ALLOWED_ENV.map(key => key.toLowerCase()))
+
+// Same test simple-git's environment guard applies, so the explicit env never
+// carries a key the guard would reject.
+function isGuardedGitEnvKey(key: string): boolean {
+ const lower = key.toLowerCase().trim()
+
+ return lower.startsWith('git_') || isGitEnvKey(lower)
+}
+
+// Explicit env for the Windows no-console host tuple: the host script needs
+// HERMES_GIT_ARGV0, and simple-git replaces the inherited env with whatever
+// `.env()` receives, so the rest of the environment is forwarded minus the
+// guarded keys that are not allow-listed.
+export function simpleGitHostEnv(base: NodeJS.ProcessEnv | undefined, gitBin: string): NodeJS.ProcessEnv {
+ const env = noConsoleGitEnv(base, gitBin)
+
+ for (const key of Object.keys(env)) {
+ if (isGuardedGitEnvKey(key) && !ALLOWED_ENV_KEYS.has(key.toLowerCase().trim())) {
+ delete env[key]
+ }
+ }
+
+ return env
+}
// GUI-launched Electron apps on macOS inherit only a minimal PATH (no
// /opt/homebrew/bin or /usr/local/bin), so `gh` — and the `git` gh shells out
@@ -74,42 +111,18 @@ function gitFor(cwd, gitBin) {
// forwards argv unchanged.
const host = windowsGitHost()
const binary = simpleGitBinary(gitBin, host)
- const unsafe = Boolean(gitBin) || Array.isArray(binary)
-
- const makeGit = () =>
- simpleGit({
- baseDir: cwd,
- binary,
- maxConcurrentProcesses: 4,
- trimmed: false,
- ...(unsafe ? { unsafe: { allowUnsafeCustomBinary: true } } : {})
- })
-
- if (!unsafe) {
- return makeGit()
- }
-
- // With the escape hatch set, simple-git still console.warns that same message on
- // every factory call — the flag only downgrades the throw to a warning. The
- // binary was resolved by this process, never supplied by the renderer, so on
- // Windows (where the standard git lives under a spaced "Program Files") that
- // warning is pure console spam. Filter exactly that message, for the
- // synchronous factory call only.
- const originalWarn = console.warn
-
- console.warn = (message?: unknown, ...rest: unknown[]) => {
- if (typeof message !== 'string' || !message.startsWith(SIMPLE_GIT_UNSAFE_BINARY_WARN)) {
- originalWarn(message, ...rest)
- }
- }
-
- try {
- const git = makeGit()
+ const unsafeBinary = Boolean(gitBin) || Array.isArray(binary)
+
+ const git = simpleGit({
+ allowEnvironment: SIMPLE_GIT_ALLOWED_ENV,
+ baseDir: cwd,
+ binary,
+ maxConcurrentProcesses: 4,
+ trimmed: false,
+ unsafe: { ...SIMPLE_GIT_ALLOWED_ENV_UNSAFE, ...(unsafeBinary ? { allowUnsafeCustomBinary: true } : {}) }
+ })
- return Array.isArray(binary) ? git.env(noConsoleGitEnv(process.env, gitBin || 'git')) : git
- } finally {
- console.warn = originalWarn
- }
+ return Array.isArray(binary) ? git.env(simpleGitHostEnv(process.env, gitBin || 'git')) : git
}
// simple-git reports renames as `old => new` (and `dir/{old => new}/f`); resolve
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index d9d51e1ff45..32a3b17e206 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -97,6 +97,7 @@
"@nanostores/react": "1.1.0",
"@novnc/novnc": "1.7.0",
"@nous-research/ui": "0.18.2",
+ "@simple-git/argv-parser": "2.0.1",
"@streamdown/code": "1.1.1",
"@streamdown/math": "1.0.2",
"@tabler/icons-react": "3.44.0",
@@ -146,7 +147,7 @@
"remark-math": "6.0.0",
"remend": "1.3.0",
"shiki": "4.3.1",
- "simple-git": "3.36.0",
+ "simple-git": "4.0.2",
"streamdown": "2.5.0",
"tailwind-merge": "3.6.0",
"tailwindcss": "4.3.3",
diff --git a/package-lock.json b/package-lock.json
index 27f38ed04ec..8673f422382 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -93,6 +93,7 @@
"@nanostores/react": "1.1.0",
"@nous-research/ui": "0.18.2",
"@novnc/novnc": "1.7.0",
+ "@simple-git/argv-parser": "2.0.1",
"@streamdown/code": "1.1.1",
"@streamdown/math": "1.0.2",
"@tabler/icons-react": "3.44.0",
@@ -142,7 +143,7 @@
"remark-math": "6.0.0",
"remend": "1.3.0",
"shiki": "4.3.1",
- "simple-git": "3.36.0",
+ "simple-git": "4.0.2",
"streamdown": "2.5.0",
"tailwind-merge": "3.6.0",
"tailwindcss": "4.3.3",
@@ -5406,18 +5407,18 @@
"license": "MIT"
},
"node_modules/@simple-git/args-pathspec": {
- "version": "1.0.3",
- "resolved": "https://registry.npmjs.org/@simple-git/args-pathspec/-/args-pathspec-1.0.3.tgz",
- "integrity": "sha512-ngJMaHlsWDTfjyq9F3VIQ8b7NXbBLq5j9i5bJ6XLYtD6qlDXT7fdKY2KscWWUF8t18xx052Y/PUO1K1TRc9yKA==",
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@simple-git/args-pathspec/-/args-pathspec-1.0.4.tgz",
+ "integrity": "sha512-EtMX6XjRWSastG2SdkmSQByPtJ9dx/NIjnHbpQPCYt62j4RmSx5rgLTGpw0YCjF5h191gZOmBfheOT23cRSFdw==",
"license": "MIT"
},
"node_modules/@simple-git/argv-parser": {
- "version": "1.1.1",
- "resolved": "https://registry.npmjs.org/@simple-git/argv-parser/-/argv-parser-1.1.1.tgz",
- "integrity": "sha512-Q9lBcfQ+VQCpQqGJFHe5yooOS5hGdLFFbJ5R+R5aDsnkPCahtn1hSkMcORX65J2Z5lxSkD0lQorMsncuBQxYUw==",
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/@simple-git/argv-parser/-/argv-parser-2.0.1.tgz",
+ "integrity": "sha512-M++IaVWrN+vYalilOHfwvT2IL3wYZtVEBQpmX6DLSOJLtxbZ+SUeIDE3IiPogzhPACLajwtxfa5rp+ZX1FczzQ==",
"license": "MIT",
"dependencies": {
- "@simple-git/args-pathspec": "^1.0.3"
+ "@simple-git/args-pathspec": "^1.0.4"
}
},
"node_modules/@sindresorhus/is": {
@@ -17180,15 +17181,15 @@
}
},
"node_modules/simple-git": {
- "version": "3.36.0",
- "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.36.0.tgz",
- "integrity": "sha512-cGQjLjK8bxJw4QuYT7gxHw3/IouVESbhahSsHrX97MzCL1gu2u7oy38W6L2ZIGECEfIBG4BabsWDPjBxJENv9Q==",
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-4.0.2.tgz",
+ "integrity": "sha512-l0sIsv9VrPwovKELFDBOj/lhmIcbMvxBk2B+hRhsMM4/VL3gKtuZvYnBNixVo+N/0HnqQx2cBdLvxnAbygHpqA==",
"license": "MIT",
"dependencies": {
"@kwsites/file-exists": "^1.1.1",
"@kwsites/promise-deferred": "^1.1.1",
- "@simple-git/args-pathspec": "^1.0.3",
- "@simple-git/argv-parser": "^1.1.0",
+ "@simple-git/args-pathspec": "1.0.4",
+ "@simple-git/argv-parser": "2.0.1",
"debug": "^4.4.0"
},
"funding": {