Repository navigation
fix(auth): require a setup token for /api/auth/init and bind 8787 to localhost - #137
Merged
Merged
Conversation
…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
force-pushed
the
fix/auth-init-setup-token
branch
from
November 3, 2026 21:19
b6bac2f to
5bad722
Compare
Merged
usinfosec
pushed a commit
to usinfosec/ARTEX
that referenced
this pull request
Nov 17, 2026
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.
Problem
POST /api/auth/init(server/auth.go, route inserver/server.go:659) accepts any caller whileauth.password_hashis empty.docker-compose.ymlpublished 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
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>authInitchecks it. The request body now carriessetup_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./setuppage has a "Setup token" field, andapi.initPassword(password, setupToken)sends it assetup_token.docker-compose.ymlnow publishes127.0.0.1:8787:8787, like 8788 on the next line.docker compose logs artex | grep "Setup token", or the terminal running./start.sh).Behavior changes for operators
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 indocker-compose.yml./api/logsalso 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-alpineon port 55432 (removed afterwards):go build -buildvcs=false ./...: OK (-buildvcs=falseonly because the worktree's git dir is a Windows path)go vet -buildvcs=false ./...: OKgofmt:server/auth.goandserver/auth_test.goare clean.server/server.gohas the same gofmt differences as onmain(pre-existing struct-tag alignment); this PR adds none.go test ./server ./agent ./cmd/artex ./config ./db -count=1:agent,cmd/artex,config,dbpass.serverfails only onTestCoreTaskLifecyclePG, which is known to fail in this environment on timing and is unrelated to this change.TestAuthInitRequiresSetupToken(server): with no password set,authInitreturns 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 existingTestAuthInitFailsClosedWhenDataSourceUnavailableandTestAuthStatusFailsClosedWhenDataSourceUnavailablestill pass.Frontend (
web/, Node 26.12.1 / npm 11.20.0 on Windows):npm ci: OK (run withHUSKY=0so thepreparescript does not write git hooks config)npx tsc --noEmit(the typecheck CI runs;package.jsonhas no typecheck script): OKnpm run lint(biome lint): exits 1 with 85 errors, the same count as onmain. The two changed files have 0 errors, and the same 2 warnings / 3 infos as onmain.biome formaton the two changed files: no new differences (the only one is pre-existing onmain).npm run build:static: OK,/setupexported.Not verified: a Docker build and run with the new port binding, and a manual click-through of
/setupin a browser against a running backend.