mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-09-30 12:39:42 +02:00
fix(security): deliver the hook secret to hooks + isolate its rate-limit bucket
Review fixes for COD-54: - Generated hook curl commands now present X-Codeman-Hook-Secret, read from the secret file AT EXECUTION TIME via $CODEMAN_HOOK_SECRET_FILE (exported into every managed session's env by tmux buildEnvExports / the direct-PTY env builders). Without this, every local hook 401'd the moment a managed tunnel came up — the enforcement existed but nothing presented the secret. Path-not-value keeps the secret off command lines and out of config files, and running sessions pick up a newly generated secret with no respawn; server.start() ensures the file exists up front. - Hook-secret failures now count into a DEDICATED per-IP bucket (hookSecretFailures) instead of the shared authFailures map. Legacy (pre-secret) hook configs fire constantly from 127.0.0.1; counting their 401s against the shared bucket would 429 every cookie-less loopback request — locking out the Basic-Auth login path (and, through a tunnel, every client, since tunneled traffic also arrives as 127.0.0.1). - docs/security-architecture.md: secret-gated hook exemption, dedicated bucket, COD-55 refusal, and the residual caveat for EXTERNAL loopback proxies (user-run cloudflared / tailscale serve), which the managed-tunnel probe cannot see. - test/cod54-hook-event-auth.test.ts: +3 tests — login path unaffected after hook-bucket exhaustion; generated hooks reference the header + $CODEMAN_HOOK_SECRET_FILE without embedding the value; env builders export the path only. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -147,4 +147,40 @@ describe('COD-54 hook-event auth — rate limiting', () => {
|
||||
}
|
||||
expect(saw429).toBe(true);
|
||||
});
|
||||
|
||||
it('hook-secret failures do NOT lock out the Basic-Auth login path (separate bucket)', async () => {
|
||||
// The previous test exhausted the hook bucket for 127.0.0.1. Legacy (pre-secret)
|
||||
// hooks fire constantly, so if they shared authFailures, every cookie-less
|
||||
// request from loopback would now 429 — locking out login (and, via a tunnel,
|
||||
// every client). Assert the login path is unaffected:
|
||||
// 1. A credential-less request still gets a 401 challenge, NOT 429.
|
||||
const unauthed = await fetch(`${baseUrl}/api/status`);
|
||||
expect(unauthed.status).toBe(401);
|
||||
// 2. Correct Basic credentials still authenticate.
|
||||
const authed = await fetch(`${baseUrl}/api/status`, {
|
||||
headers: { Authorization: 'Basic ' + Buffer.from(`${TEST_USER}:${TEST_PASS}`).toString('base64') },
|
||||
});
|
||||
expect(authed.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
describe('COD-54 secret delivery — generated hooks + session env present the secret', () => {
|
||||
it('generated hook curl commands send the secret header, read from the file at exec time', async () => {
|
||||
const { generateHooksConfig } = await import('../src/hooks-config.js');
|
||||
const config = generateHooksConfig();
|
||||
const commands = JSON.stringify(config);
|
||||
// Header present, value sourced from $CODEMAN_HOOK_SECRET_FILE (not embedded).
|
||||
expect(commands).toContain(HOOK_SECRET_HEADER);
|
||||
expect(commands).toContain('$CODEMAN_HOOK_SECRET_FILE');
|
||||
expect(commands).not.toContain(getHookSecret());
|
||||
});
|
||||
|
||||
it('session env builders export CODEMAN_HOOK_SECRET_FILE (path only, never the value)', async () => {
|
||||
const { buildClaudeEnv, buildShellEnv } = await import('../src/session-cli-builder.js');
|
||||
const claudeEnv = buildClaudeEnv('test-session');
|
||||
const shellEnv = buildShellEnv('test-session');
|
||||
expect(claudeEnv.CODEMAN_HOOK_SECRET_FILE).toMatch(/hook-secret$/);
|
||||
expect(shellEnv.CODEMAN_HOOK_SECRET_FILE).toMatch(/hook-secret$/);
|
||||
expect(JSON.stringify(claudeEnv)).not.toContain(getHookSecret());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user