Skip to content

Add optional password login (MAILGREP_PASSWORD) - #3

Merged
samvdst merged 1 commit into
mainfrom
password-auth
Oct 5, 2026
Merged

samvdst merged 1 commit into
mainfrom
password-auth

Conversation

@samvdst

@samvdst samvdst commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Adds an optional single shared password.

  • MAILGREP_PASSWORD set → every /api/* route except /api/auth, /api/login, /api/logout returns 401 without a valid session. Unset → unchanged behaviour plus a startup warning.
  • Sessions: stateless <expiry>.<hmac> cookie (HttpOnly, SameSite=Strict, Secure behind an HTTPS proxy), 30 days, HMAC key derived from the password + MAILGREP_KEY, so rotating either signs everyone out. No session storage.
  • Password check is constant-time; failed attempts are serialised and delayed 500 ms.
  • SPA: sign-in screen when /api/auth says so or any query/mutation gets a 401; sign-out button in settings. The sandboxed message iframe (allow-same-origin) keeps the cookie, so inline images and attachments still work.
  • Docs: README, SECURITY.md, docker-compose.yml.

Tested: cargo test (new unit + HTTP-level login test), npm run build (incl. tsc), and a headless-Chromium run of wrong password → sign in → reload → sign out against the real binary.

🤖 Generated with Claude Code

A single shared password gates every /api route except login, logout and
auth status. Sessions are stateless HMAC-signed HttpOnly SameSite=Strict
cookies (30 days), keyed on the password and MAILGREP_KEY, so changing
either signs everyone out. Failed attempts are serialised and delayed.
Unset keeps today's behaviour, with a startup warning.

The SPA shows a sign-in screen whenever /api/auth or any request returns
401, and settings gets a sign-out button.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@samvdst
samvdst merged commit 8c4fdc0 into main Oct 5, 2026
1 check passed
@samvdst
samvdst deleted the password-auth branch October 5, 2026 21:31
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