The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
test(agent-data-home): pin the trusted root that moves with CLAUDE_CONFIG_DIR
basil-k-aji-dev14d54a928522
diff --git a/tests/lib/agent-data-home.test.js b/tests/lib/agent-data-home.test.jsindex 8aeac883b..f867042ca 100644--- a/tests/lib/agent-data-home.test.js+++ b/tests/lib/agent-data-home.test.js@@ -541,6 +541,59 @@ function runTests() {});})) passed++; else failed++;+ if (test('security: the trusted root moves with CLAUDE_CONFIG_DIR but still confines the project config', () => {+ // getDefaultClaudeAgentDataHome() is not only a default: it is one of the two+ // roots resolveAllowedProjectConfigHome() will accept. Following+ // CLAUDE_CONFIG_DIR moves that boundary with the profile, so the containment+ // it enforces has to hold at the new location and nowhere else.+ const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-agent-data-home-cfgdir-'));+ const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-agent-data-home-cfgdir-user-'));+ const profileDir = path.join(homeDir, '.claude-profile-x');+ const configPath = path.join(projectDir, '.cursor', 'ecc-agent-data.json');+ fs.mkdirSync(path.dirname(configPath), { recursive: true });++ try {+ withEnv({+ ECC_AGENT_DATA_HOME: undefined,+ CLAUDE_CONFIG_DIR: profileDir,+ HOME: homeDir,+ USERPROFILE: undefined,+ }, () => {+ const agentDataHome = require('../../scripts/lib/agent-data-home');++ // Inside the relocated root: accepted.+ fs.writeFileSync(+ configPath,+ JSON.stringify({ agentDataHome: path.join(profileDir, 'nested') }),+ 'utf8'+ );+ assert.strictEqual(+ agentDataHome.readProjectConfigAt(configPath),+ path.join(profileDir, 'nested')+ );++ // The old default is no longer a root, and neither is anything outside+ // the new one. A traversal out of the relocated root stays rejected.+ const outside = [+ path.join(homeDir, '.claude'),+ path.join(profileDir, '..', 'escaped'),+ path.join(homeDir, 'arbitrary-agent-data'),+ ];+ for (const candidate of outside) {+ fs.writeFileSync(configPath, JSON.stringify({ agentDataHome: candidate }), 'utf8');+ const { result, messages } = captureConsoleErrors(+ () => agentDataHome.readProjectConfigAt(configPath)+ );+ assert.strictEqual(result, null, `expected rejection for ${candidate}`);+ assert.ok(messages.some(message => message.includes('Ignoring unsafe agent data project config')));+ }+ });+ } finally {+ fs.rmSync(projectDir, { recursive: true, force: true });+ fs.rmSync(homeDir, { recursive: true, force: true });+ }+ })) passed++; else failed++;+console.log(`\n=== Test Results ===\nPassed: ${passed}\nFailed: ${failed}\n`);if (failed > 0) process.exit(1);}