Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(security): the daemon's git ignores a repository's fsmonitor (OH-16) (#356)

0xken15773396170870
diff --git a/cli/src/lib/gitProject.spec.ts b/cli/src/lib/gitProject.spec.ts
index be3ec9f78..c21abaa45 100644
--- a/cli/src/lib/gitProject.spec.ts
+++ b/cli/src/lib/gitProject.spec.ts
@@ -48,6 +48,16 @@ describe('launch Git preparation', { timeout: 30_000 }, () => {
expect(encryptRpcResult('git_project_info_result')).toBe(true)
})
+ it('never runs a program the repository names as its fsmonitor', async () => {
+ const marker = join(root, 'fsmonitor-ran')
+ const hook = join(root, 'fsmonitor.sh')
+ await writeFile(hook, `#!/bin/sh\ntouch '${marker}'\n`, { mode: 0o755 })
+ await git('config', 'core.fsmonitor', hook)
+ await readGitProject(repo)
+ await prepare('branch', 'refs/heads/feature')
+ await expect(readFile(marker)).rejects.toThrow()
+ })
+
it('reads local and remote branches without switching or creating anything', async () => {
expect(await readGitProject(repo)).toMatchObject({ isGit: true, branch: 'main', branches: [
{ ref: 'refs/heads/feature', name: 'feature', remote: false },
diff --git a/cli/src/lib/gitProject.ts b/cli/src/lib/gitProject.ts
index b4fd510f5..57ae93258 100644
--- a/cli/src/lib/gitProject.ts
+++ b/cli/src/lib/gitProject.ts
@@ -17,7 +17,9 @@ export function validGitPath(path: unknown): path is string {
async function git(path: string, args: string[], timeout = 4000): Promise<string> {
const env = { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'Never', GIT_OPTIONAL_LOCKS: '0' }
for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', 'GIT_NAMESPACE', 'GIT_PREFIX']) delete (env as NodeJS.ProcessEnv)[key]
- return (await exec('git', ['--no-optional-locks', '-C', path, ...args], {
+ // core.fsmonitor names a program git runs on status/diff; a repository's own config must not choose
+ // one for the daemon (same guard as projectPreview.ts).
+ return (await exec('git', ['--no-optional-locks', '-c', 'core.fsmonitor=false', '-C', path, ...args], {
timeout, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024,
env,
})).stdout.replace(/\r?\n$/, '')