Repository navigation
Conversation
…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]>
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.goauthInit, route inserver/server.go) sets the admin password wheneverauth.password_hashis empty, and it checks nothing else.docker-compose.ymlpublished"8787:8787"on all interfaces. Anyone who reached the port before the owner opened/setupcould take the instance.Fix
server/auth.go,server/server.go): at startupNewcallsinitSetupToken. 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>authInitnow requiressetup_tokenin 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.web/src/app/(auth)/setup/page.tsxhas a new "Setup token" field, required before submit, andapi.initPasswordsends it assetup_token. The mock handler needs no change."8787:8787"becomes"127.0.0.1:8787:8787", the same as 8788 on the next line.User-visible changes
/setupasks for the setup token. Read it from the server log, for exampledocker compose logs artex | grep "Setup token", or the terminal runningstart.sh. Existing installs that already have a password are not affected.http://<host-ip>:8787from 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 localstart.shrun is unchanged: it still listens on:8787(the-addrdefault).Verification
Run in WSL (kali), Go 1.26.7, against a throwaway
postgres:16-alpinecontainer on port 55432 (removed afterwards):go build -buildvcs=false ./...: OKgo vet ./...: OKgofmt: the changed files are clean.server/server.gohas an older, unrelated alignment drift around line 1504 that is not touched here.go test ./server -run '^Test(Auth|ValidatePassword)' -v: the existingTestAuthStatusFailsClosed…andTestAuthInitFailsClosed…still pass. The newTestAuthInitRequiresSetupTokenpasses: 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 exceptTestCoreTaskLifecyclePG, which is known to fail in this environment for timing reasons and fails the same way without this change.Not verified:
web/node_moduleswas not installed, and I did not runnpm ci.docker compose upwith the new port binding./setuppage in a browser.🤖 Generated with Claude Code