Skip to content

fix(security): harden headers, logins, sessions and logs before launch - #11

Merged
coko7 merged 1 commit into
mainfrom
fix/security-hardening
Nov 29, 2026
Merged

coko7 merged 1 commit into
mainfrom
fix/security-hardening

Conversation

@coko7

@coko7 coko7 commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Fixes 1–5 from the pre-launch security review.

  1. Browser headers on every response:
    • Content-Security-Policy: default-src 'self'; img-src 'self' https://http.cat; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'
      • 'unsafe-inline' for styles is there because templates use style= attributes.
      • The http.cat 404 picture stays allowed.
    • Referrer-Policy: same-origin
    • Strict-Transport-Security: max-age=31536000, only when AOT_BASE_URL is https.
    • nosniff moves into the same middleware.
  2. No more lockouts by strangers: the login rate limit counts per email and IP (10 per 15 min), so wrong passwords from someone else no longer lock the owner out. The per-IP limit (30 per 15 min) stays. There's no CDN in front of Traefik, so the IP is the real client.
  3. A password change logs out old sessions: aot user reset-password (via db::set_password_hash) sets users.sessions_revoked_at. Sessions that logged in before that time are dropped on their next request. Migration 0002_sessions_revoked_at.sql adds the column.
  4. No personal data in logs: a first OAuth login logs only the display name (a Microsoft account name is an email). An unexpected provider reply logs only the JSON keys, not the values.
  5. Signup race: two simultaneous signups with one email now give the second one "An account with this email already exists" instead of a 500.

Not changed: the http.cat 404 picture (kept on purpose), POSTs without an Origin header (every current browser sends one), container hardening.

Check

  • New tests:
    • headers on a page, the 404 page and a static file, with no HSTS over http;
    • another IP isn't locked out after 10 failures;
    • a password change logs out the old session and the new password works;
    • the duplicate identity is recognised.
  • Home and 404 pages loaded in Chromium under the new CSP: no CSP violations. The countdown script, font, inline styles and the http.cat picture all work.
  • cargo audit: no vulnerabilities, two "unmaintained" warnings (basic-toml, chrono) with no fix available.
  • fmt, clippy, 31 tests pass.

Pre-launch, so no version bump.

Co-Authored-By: lazytrek 352825308+lazytrek@users.noreply.github.com

- CSP (self only, plus http.cat for the 404 cat; no framing), Referrer-Policy
  same-origin, HSTS when served over https, on every response.
- Login rate limit counts per email AND IP, so strangers can't lock an
  owner out; the per-IP limit stays.
- A password change (aot user reset-password) logs out every existing
  session of that user (migration 0002: users.sessions_revoked_at).
- OAuth logins no longer log the account name (a Microsoft UPN is an
  email) or the provider's profile JSON.
- Two simultaneous signups with one email: the loser sees "already
  exists" instead of a 500.

Co-Authored-By: lazytrek <352825308+lazytrek@users.noreply.github.com>
@coko7
coko7 merged commit 33926ba into main Nov 29, 2026
2 checks passed
@coko7
coko7 deleted the fix/security-hardening branch November 29, 2026 17:30
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