Skip to content

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

Closed
BaaRai wants to merge 1 commit into
mainfrom
fix/auth-init-setup-token
Closed

BaaRai wants to merge 1 commit 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 authInit, route in server/server.go) sets the admin password whenever auth.password_hash is empty, and it checks nothing else. docker-compose.yml published "8787:8787" on all interfaces. Anyone who reached the port before the owner opened /setup could take the instance.

Fix

  • Setup token (server/auth.go, server/server.go): at startup New calls initSetupToken. When no password is set, it generates a one-time token (crypto/rand.Text(), 128 bits) and logs it:
    [auth] no admin password set. Setup token for the /setup page: <token>
    authInit now requires setup_token in the JSON body and compares it in constant time. A missing or wrong token gets 403, and nothing is written. If a password already exists at startup, or the read fails, no token is issued and init stays closed until a restart.
  • UI (part of this PR): web/src/app/(auth)/setup/page.tsx has a new "Setup token" field, required before submit, and api.initPassword sends it as setup_token. The mock handler needs no change.
  • Compose: "8787:8787" becomes "127.0.0.1:8787:8787", the same as 8788 on the next line.
  • README: the install note says where to find the token.

User-visible changes

  • New setup step: on a fresh install, /setup asks for the setup token. Read it from the server log, for example docker compose logs artex | grep "Setup token", or the terminal running start.sh. Existing installs that already have a password are not affected.
  • Remote access: with the Docker Compose deployment, port 8787 now listens only on the host's loopback. Anyone who opened http://<host-ip>:8787 from another machine loses that access and must use a reverse proxy on the host (see the README's reverse proxy section) or an SSH tunnel. A local start.sh run is unchanged: it still listens on :8787 (the -addr default).

Verification

Run in WSL (kali), Go 1.26.7, against a throwaway postgres:16-alpine container on port 55432 (removed afterwards):

  • go build -buildvcs=false ./...: OK
  • go vet ./...: OK
  • gofmt: the changed files are clean. server/server.go has an older, unrelated alignment drift around line 1504 that is not touched here.
  • go test ./server -run '^Test(Auth|ValidatePassword)' -v: the existing TestAuthStatusFailsClosed… and TestAuthInitFailsClosed… still pass. The new TestAuthInitRequiresSetupToken passes: no token gets 403, a wrong token gets 403, neither writes a password, the right token gets 200 with a JWT, and a restart with a password set issues no token. The test skips instead of touching a database that already holds a password, and removes the hash it set.
  • go test ./server ./agent ./cmd/artex ./config ./db -count=1: all pass except TestCoreTaskLifecyclePG, which is known to fail in this environment for timing reasons and fails the same way without this change.

Not verified:

  • the frontend build, type check and biome lint. web/node_modules was not installed, and I did not run npm ci.
  • a real docker compose up with the new port binding.
  • the /setup page in a browser.

🤖 Generated with Claude Code

…localhost

POST /api/auth/init set the admin password for anyone who reached the
port while no password existed, with no other check. docker-compose
published 8787 on all interfaces, so a fresh install could be claimed
from the network before its owner opened /setup.

At startup, when no password is set, the server now generates a one-time
setup token and prints it to its log; authInit rejects requests without
it (403). The /setup page gets a "Setup token" field and sends it as
setup_token. docker-compose binds 8787 to 127.0.0.1, like 8788 already
is. README notes where to find the token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BaaRai BaaRai closed this Nov 3, 2026
@BaaRai
BaaRai deleted the fix/auth-init-setup-token branch November 3, 2026 20:31
@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