Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(init): reject machine-home symlink aliases [I1,I2]
Corey Olson61af19a9ec9d
diff --git a/src/init.js b/src/init.jsindex 4726b5dd..17df72fb 100644--- a/src/init.js+++ b/src/init.js@@ -5,10 +5,10 @@* write.*/import {- accessSync, appendFileSync, constants as fsConstants, existsSync, mkdirSync,- readdirSync, readFileSync, statSync, writeFileSync,+ accessSync, appendFileSync, constants as fsConstants, existsSync, lstatSync, mkdirSync,+ readdirSync, readFileSync, realpathSync, statSync, writeFileSync,} from 'node:fs';-import { delimiter, basename, isAbsolute, join, parse, relative, resolve, sep } from 'node:path';+import { delimiter, basename, dirname, isAbsolute, join, parse, relative, resolve, sep } from 'node:path';import { userInfo } from 'node:os';import { CONFIG_FILE, COORDINATOR, doctrineFile, loadConfig } from './config.js';import { loadDoctrine } from './doctrine.js';@@ -23,11 +23,33 @@ import {const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';+/** Resolve a directory through symlinks, retaining a missing suffix for a not-yet-created private home. */+function canonicalDirectoryPath(candidate) {+ let cursor = resolve(candidate);+ const missing = [];+ while (true) {+ try {+ const physical = realpathSync(cursor);+ if (!statSync(physical).isDirectory()) return null;+ return resolve(physical, ...missing.reverse());+ } catch (error) {+ if (error.code !== 'ENOENT') return null;+ try { lstatSync(cursor); return null; } catch (statError) {+ if (statError.code !== 'ENOENT') return null;+ }+ const parent = dirname(cursor);+ if (parent === cursor) return null;+ missing.push(basename(cursor));+ cursor = parent;+ }+ }+}+/** Keep an automatic machine-home write grant below the OS user home and away from filesystem roots. */export function machineHomeWriteScopeIsNarrow(machinePath, userHome = userInfo().homedir) {- const target = resolve(machinePath);- const home = resolve(userHome);- if (target === parse(target).root) return false;+ const target = canonicalDirectoryPath(machinePath);+ const home = canonicalDirectoryPath(userHome);+ if (!target || !home || target === parse(target).root) return false;const homeFromTarget = relative(target, home);const targetContainsHome = homeFromTarget === '' || (homeFromTarget !== '..'&& !homeFromTarget.startsWith(`..${sep}`) && !isAbsolute(homeFromTarget));diff --git a/test/init-permissions.test.js b/test/init-permissions.test.jsindex 46646a78..ea4fa679 100644--- a/test/init-permissions.test.js+++ b/test/init-permissions.test.js@@ -1,6 +1,6 @@/** Init adds only the requested project-local agent loop permissions and can skip them [I1,I2]. */import assert from 'node:assert/strict';-import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, parse, resolve } from 'node:path';import { test } from 'node:test';@@ -87,6 +87,18 @@ test('init grants the agent the permissions the Pullboard loop needs [I1,I2]', tassert.equal(machineHomeWriteScopeIsNarrow(resolve(syntheticHome, '..'), syntheticHome), false, 'an ancestor containing the OS home is never granted');assert.equal(machineHomeWriteScopeIsNarrow(parse(syntheticHome).root, syntheticHome), false, 'a filesystem root is never granted');+ const scopeFixture = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-machine-home-symlink-')));+ t.after(() => rmSync(scopeFixture, { recursive: true, force: true }));+ const simulatedHome = join(scopeFixture, 'os-home');+ mkdirSync(simulatedHome);+ const homeAlias = join(scopeFixture, 'home-alias');+ symlinkSync(simulatedHome, homeAlias, 'dir');+ assert.equal(machineHomeWriteScopeIsNarrow(homeAlias, simulatedHome), false, 'a symlink that grants the entire OS home is refused');+ assert.equal(machineHomeWriteScopeIsNarrow(join(homeAlias, '.pullboard'), simulatedHome), true, 'a missing private machine-home below the canonical home remains eligible');+ const danglingAlias = join(scopeFixture, 'dangling-home-alias');+ symlinkSync(join(scopeFixture, 'missing-home'), danglingAlias, 'dir');+ assert.equal(machineHomeWriteScopeIsNarrow(danglingAlias, simulatedHome), false, 'an unresolvable existing symlink fails closed');+const fresh = initFixture(t);const freshInit = fresh.init();assert.equal(freshInit.code, 0, freshInit.stderr);