Repository navigation
Scope the session cookie to the instance - #5
Merged
Merged
Conversation
Running several Explo instances on one host -- the usual unraid setup,
one container per port -- logged the user out of whichever instance they
had visited first. Loading the second instance was enough to break the
first; no login was needed.
Cookies are scoped by host, not by port (RFC 6265 section 8.5). Every
instance wrote its session ID to a cookie literally named "session" for
that host, so the browser kept one entry and each instance overwrote the
last. Sessions live in each process's own in-memory store, so an ID
minted by one instance means nothing to the next: start() failed to read
it, minted a fresh unauthenticated session, and the user was bounced to
the login screen. The same collision fails CSRF checks, since the token
belongs to whichever session was written last.
The cookie name is now derived from WEB_ADDR -- explo_session_7288 --
which is exactly what distinguishes instances on one host. UI_COOKIE_NAME
overrides it for deployments that cannot be told apart this way, such as
several instances behind one reverse proxy on the same host and port. An
address with no readable port falls back to the shared name rather than
emitting a malformed cookie, and the derived suffix is sanitized because
WEB_ADDR may name a service ("http") rather than a number.
Existing sessions do not survive the rename: everyone logs in once more
after upgrading, and the stale "session" cookie is left in the jar until
the browser expires it. Nothing reads it any more.
The regression test drives two instances through one cookie jar, which
is what a browser does, and asserts that visiting the second leaves the
first logged in.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
golangci-lint's errcheck rejected the bare deferred Close. The helper reports the failure instead of discarding it, matching how the rest of the suite treats errors it does not expect. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Fixes logins breaking when several Explo instances run on one host — the usual unraid setup, one container per port.
Root cause
Cookies are scoped by host, not by port (RFC 6265 §8.5). Every instance wrote its session ID to a cookie named literally
sessionfor that host, so the browser kept a single entry and each instance overwrote the last.Sessions live in each process's own in-memory store, so an ID minted by instance A means nothing to instance B.
SessionManager.startfailed to read it, minted a fresh unauthenticated session, and the user was bounced to the login screen. The same collision fails CSRF checks, sincecsrf_tokenbelongs to whichever session was written last.Loading the second instance was enough to break the first — no login required.
Fix
The cookie name is derived from
WEB_ADDR(explo_session_7288), which is exactly what distinguishes instances on one host.UI_COOKIE_NAMEoverrides it for deployments that can't be told apart that way — several instances behind one reverse proxy on the same host and port.An address with no readable port falls back to the shared
explo_sessionrather than emitting a malformed cookie, and the suffix is sanitized becauseWEB_ADDRmay name a service (:http) rather than a number.Upgrade note
Existing sessions don't survive the rename: everyone logs in once more after upgrading. The stale
sessioncookie is left in the jar until the browser expires it; nothing reads it any more.No chart change needed —
env/extraEnvalready pass arbitrary variables through.Testing
The regression test drives two instances through a single
cookiejar, which is what a browser does, and asserts that visiting the second leaves the first logged in. Verified it fails against the old fixed name (first instance = 401, want 200 -- the second instance clobbered its session cookie) and passes with the fix.Also covers every listen-address form (
:7288,0.0.0.0:7288,[::]:7288,:http, no port, empty, unsafe characters) and that the session actually round-trips under the derived name.go build ./...,go vet ./src/...andgo test ./src/...all pass.🤖 Generated with Claude Code