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
test(view): cover LAN API host authorization [H19]
Corey Olsond743ef218961
diff --git a/test/api.test.js b/test/api.test.jsindex a2d4008d..5f0409d8 100644--- a/test/api.test.js+++ b/test/api.test.js@@ -141,6 +141,40 @@ test('[A2] the local API admits only its listed origins', async (t) => {assert.equal((await apiError(defaultOrigin, 403)).code, 'API_ORIGIN', 'omitting the option preserves same-origin-only behavior');});+test('local API admits only configured literal IPv4 hosts at their own origin [H19]', async (t) => {+ const box = project();+ const assigned = '192.168.7.9';+ const configured = await startLocalHandler(t, box, { allowedHosts: [assigned] });+ const port = new URL(configured.origin).port;+ const ownHost = `${assigned}:${port}`;+ const ownOrigin = `http://${ownHost}`;+ const allowed = await apiFetch(configured, '/api/v1/boards', { headers: { host: ownHost, origin: ownOrigin } });+ assert.equal(allowed.status, 200, 'the exact configured IPv4 Host and same Origin reach the regular API');+ assert.equal((await allowed.json()).boards.length, 1, 'the allowed host receives the fixture board');++ const loopback = await apiFetch(configured, '/api/v1/boards');+ assert.equal(loopback.status, 200, 'enabling one LAN host preserves the existing loopback host');++ const foreignHost = await apiFetch(configured, '/api/v1/boards', {+ headers: { host: `192.168.7.10:${port}`, origin: `http://192.168.7.10:${port}` },+ });+ assert.equal((await apiError(foreignHost, 401)).code, 'AUTH_REQUIRED', 'a different literal IPv4 Host is refused');++ const foreignOrigin = await apiFetch(configured, '/api/v1/boards', {+ headers: { host: ownHost, origin: 'https://foreign.invalid' },+ });+ assert.equal((await apiError(foreignOrigin, 403)).code, 'API_ORIGIN', 'a foreign Origin is refused even for the allowed Host');++ const defaulted = await startLocalHandler(t, box);+ const notImplicitlyAllowed = await apiFetch(defaulted, '/api/v1/boards', { headers: { host: ownHost, origin: ownOrigin } });+ assert.equal((await apiError(notImplicitlyAllowed, 401)).code, 'AUTH_REQUIRED', 'omitting the allowlist preserves loopback-only Host authority');++ for (const host of ['localhost', '0.0.0.0', '2001:db8::1']) {+ assert.throws(() => createLocalApiHandler({ secret: randomUUID(), getPort: () => 1, runCommand: main,+ projects: () => [], allowedHosts: [host] }), TypeError, `non-IPv4 or wildcard host ${host} is rejected at construction`);+ }+});+/** Quote a literal executable path for the fixture hook's POSIX shim. */function shellWord(value) {return "'" + value.replace(/'/g, "'\\''") + "'";@@ -662,6 +696,7 @@ async function startLocalHandler(t, box, options = {}) {runCommand: options.runCommand ?? main,projects: () => [{ root: box.repo, name: 'API fixture', project: '', added: '2026-01-01T00:00:00.000Z' }],...(options.allowedOrigins === undefined ? {} : { allowedOrigins: options.allowedOrigins }),+ ...(options.allowedHosts === undefined ? {} : { allowedHosts: options.allowedHosts }),...(options.onStateBuild === undefined ? {} : { onStateBuild: options.onStateBuild }),...(options.onItemBuild === undefined ? {} : { onItemBuild: options.onItemBuild }),...(options.stateDetail === undefined ? {} : { stateDetail: options.stateDetail }),