Skip to content

fix(auth): require a setup token for /api/auth/init and bind 8787 to localhost - #137

Merged
BaaRai merged 2 commits into
mainfrom
fix/auth-init-setup-token
Nov 3, 2026
Merged

BaaRai merged 2 commits into
mainfrom
fix/auth-init-setup-token

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Problem

POST /api/auth/init (server/auth.go, route in server/server.go:659) accepts any caller while auth.password_hash is empty. docker-compose.yml published 8787 on all interfaces, so on a fresh install anyone who reached the port before the operator could set the admin password and take the instance (agent shells, stored keys, findings).

Fix

  • Setup token. In server.New, when no admin password is set, the server generates a random 128-bit one-time token (crypto/rand, hex) and writes it to the server log:
    [auth] no admin password is set. Setup token for the /setup page: <token>
  • authInit checks it. The request body now carries setup_token. It is compared in constant time (crypto/subtle); a missing or wrong token gets 403 (not 401, because the frontend treats any 401 as an expired session and redirects to /login). Once the password is stored, the token is cleared, so it cannot be reused. Without an active token, init is refused. The existing checks are unchanged: an already-set password still returns 403, and a failed database read still returns 503.
  • Frontend. The /setup page has a "Setup token" field, and api.initPassword(password, setupToken) sends it as setup_token.
  • Compose. docker-compose.yml now publishes 127.0.0.1:8787:8787, like 8788 on the next line.
  • README. One line on where to find the token (docker compose logs artex | grep "Setup token", or the terminal running ./start.sh).

Behavior changes for operators

  • The setup step is new. First-run setup now needs the token from the server log. Existing installs that already have a password see no change.
  • Remote access to 8787 now needs a reverse proxy or an SSH tunnel (for example ssh -L 8787:127.0.0.1:8787 host) on Docker installs. The README's reverse-proxy section (proxy_pass http://127.0.0.1:8787) still works as is. To keep the old behavior, change the port mapping back in docker-compose.yml.
  • The token appears in the server log, which /api/logs also serves. That endpoint needs a login, which is only possible after a password is set, and by then the token no longer works.

Verification

WSL (kali), Go 1.26.7, throwaway postgres:16-alpine on port 55432 (removed afterwards):

  • go build -buildvcs=false ./...: OK (-buildvcs=false only because the worktree's git dir is a Windows path)
  • go vet -buildvcs=false ./...: OK
  • gofmt: server/auth.go and server/auth_test.go are clean. server/server.go has the same gofmt differences as on main (pre-existing struct-tag alignment); this PR adds none.
  • go test ./server ./agent ./cmd/artex ./config ./db -count=1: agent, cmd/artex, config, db pass. server fails only on TestCoreTaskLifecyclePG, which is known to fail in this environment on timing and is unrelated to this change.
  • New test TestAuthInitRequiresSetupToken (server): with no password set, authInit returns 403 for a missing, empty or wrong token and stores nothing. It returns 200 with a JWT for the right token, and 403 when the same token is reused. It fails when the token check is bypassed and passes with it. The existing TestAuthInitFailsClosedWhenDataSourceUnavailable and TestAuthStatusFailsClosedWhenDataSourceUnavailable still pass.

Frontend (web/, Node 26.12.1 / npm 11.20.0 on Windows):

  • npm ci: OK (run with HUSKY=0 so the prepare script does not write git hooks config)
  • npx tsc --noEmit (the typecheck CI runs; package.json has no typecheck script): OK
  • npm run lint (biome lint): exits 1 with 85 errors, the same count as on main. The two changed files have 0 errors, and the same 2 warnings / 3 infos as on main.
  • biome format on the two changed files: no new differences (the only one is pre-existing on main).
  • npm run build:static: OK, /setup exported.

Not verified: a Docker build and run with the new port binding, and a manual click-through of /setup in a browser against a running backend.

BaaRai and others added 2 commits November 3, 2026 22:18
…localhost

POST /api/auth/init accepted any caller while auth.password_hash was empty,
so whoever reached port 8787 first could set the admin password and take the
instance. When no password is set at startup, the server now generates a
random one-time setup token and writes it to the server log. authInit
compares it in constant time, rejects a missing or wrong token with 403, and
clears it once the password is stored.

The setup page has a field for the token and api.initPassword sends it.
docker-compose publishes 8787 on 127.0.0.1 only, like 8788. README says where
to find the token.
Publishing 127.0.0.1:8787 removed the only working access path for installs
reached through a host or WSL IP, without an obvious way back. Keep loopback as
the default and let ARTEX_BIND_ADDR override it (0.0.0.0 restores the old
behaviour; the setup token still protects the first-run claim).
@BaaRai
BaaRai force-pushed the fix/auth-init-setup-token branch from b6bac2f to 5bad722 Compare November 3, 2026 21:19
@BaaRai
BaaRai merged commit 23cf14c into main Nov 3, 2026
2 checks passed
@BaaRai BaaRai mentioned this pull request Nov 4, 2026
usinfosec pushed a commit to usinfosec/ARTEX that referenced this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant