feat(auth): password login page for hosted deployments#101
Merged
Conversation
Replace the optional browser Basic-Auth popup with a proper /login page for hosted (Docker/Railway) deployments, and make the gate mandatory there. - lib/auth/session.ts: HMAC-SHA256 signed, 30-day expiring session token via Web Crypto so the same module runs in the Edge proxy and Node actions. The HMAC key is MINITOR_PASSWORD, so rotating the password invalidates every session. sanitizeNext() blocks open redirects from the ?next= param. - app/login: server page (redirects away if already authed / no password), client form (useActionState), and login/logout server actions that set and clear an HttpOnly, SameSite=Lax, Secure session cookie. - proxy.ts: migrate middleware.ts to the Next 16 proxy convention and gate on the session cookie — pages redirect to /login?next=…, /api/* returns 401, /login and static assets pass through. Fail closed: MINITOR_HOSTED with no password serves a 503 lock screen; /api/health stays open for probes. - settings-dialog: add a "Log out" button on hosted instances. - test/session.test.ts: 9 tests for sign/verify/expiry/tamper/open-redirect. - README + docker-compose: document that MINITOR_PASSWORD is required in hosted mode.
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.
What
Replaces the optional browser Basic-Auth popup with a proper
/loginpage for hosted (Docker/Railway) deployments, and makes the password gate mandatory there (fail-closed).Requested follow-up to #100.
Behaviour
MINITOR_PASSWORDset, no session307 /login?next=…,/api/*→401/login503lock screen (never an open public instance)/api/health200(platform probes pass, even when locked)./minitor(not hosted, no password)How
lib/auth/session.ts— HMAC-SHA256 signed, 30-day expiring session token via Web Crypto (same module runs in the Edge proxy and Node actions). HMAC key isMINITOR_PASSWORD, so rotating the password invalidates every session.sanitizeNext()blocks open redirects.app/login/— server page, client form (useActionState), andlogin/logoutserver actions setting anHttpOnly/SameSite=Lax/Securecookie.proxy.ts— migratesmiddleware.tsto the Next 16 proxy convention and gates on the session cookie.settings-dialog.tsx— "Log out" button on hosted instances.README,docker-compose.yml) note the password is required in hosted mode.Verify
next buildclean (TypeScript passes), no moremiddleware-deprecation warning.node .next/standalone/server.js) for every row in the table above.