feat(security): SEC-05 - Host/IP allowlist + mandatory ADMIN_TOKEN for non-localhost#62
Merged
Killea merged 1 commit intoKillea:mainfrom Mar 19, 2026
Merged
Conversation
…non-localhost - Fail-fast: startHttpServer() aborts with process.exit(1) when HOST != 127.0.0.1 or SHOW_AD=true and AGENTCHATBUS_ADMIN_TOKEN is not set - IP allowlist middleware: AGENTCHATBUS_ALLOWED_HOSTS (comma-separated IPs/IPv4 CIDRs) blocks non-loopback requests with 403; loopback always bypasses - SHOW_AD write guard: when SHOW_AD=true, all write/delete endpoints require X-Admin-Token header; agent-auth endpoints and GETs remain open - Token suppression: /api/agents/register strips token from response when SHOW_AD=true to prevent leakage in public demo mode - New helpers in env.ts: isNonLocalhostDeployment, isIpAllowed, parseAllowedHosts - 29 new tests in test_sec05_host_security.test.ts; 523/523 total tests pass - All changes backward-compatible: localhost deployments unaffected Backward-compatible: localhost users see zero change in behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
startHttpServer()aborts withprocess.exit(1)whenHOST != 127.0.0.1(orSHOW_AD=true) andAGENTCHATBUS_ADMIN_TOKENis not set — prevents accidental unsecured public deploymentAGENTCHATBUS_ALLOWED_HOSTS(comma-separated IPs/IPv4 CIDRs) blocks non-loopback requests with 403; loopback always bypassesSHOW_AD=true, all write/delete endpoints requireX-Admin-Tokenheader; agent-auth endpoints (register,heartbeat,resume,unregister,POST /api/threads,POST /api/threads/:id/messages) and GET endpoints remain open/api/agents/registerstripstokenfrom JSON response whenSHOW_AD=trueto prevent credential leakage in public demo modeMotivation
SHOW_AD=truecurrently only disables UI buttons (Close/Delete) client-side. Anyone can still callDELETE /api/threads/{id}directly via REST. This PR adds server-side enforcement to complement the existing UI-level guard.All changes are backward-compatible: localhost users (
HOST=127.0.0.1,SHOW_AD=false) see zero change in behavior.New env vars
AGENTCHATBUS_ALLOWED_HOSTSTest plan
npm testpasses (29 new tests intest_sec05_host_security.test.ts, 523/523 total)HOST=0.0.0.0and noAGENTCHATBUS_ADMIN_TOKEN— should refuse to startSHOW_AD=trueandAGENTCHATBUS_ADMIN_TOKEN=secret,DELETE /api/threads/{id}returns 401 without header, 200 withX-Admin-Token: secretPOST /api/agents/registerreturns notokenfield whenSHOW_AD=true127.0.0.1regardless ofSHOW_AD