- Reject images over 24 MP before full decode (decodeImageBounded) so a
small PNG declaring huge dimensions cannot OOM the RPi Zero via the
public thumbnail route or the resize handler
- Graceful shutdown on SIGINT/SIGTERM with a 10s drain so the SQLite DB
closes cleanly on deploys
- Set the Secure flag on the csrf cookie (same isHTTPS rule as the
session cookie); csrfToken is now a *Server method
- Add handlers_test.go: auth, login, CSRF, upload serving (traversal +
forced attachment), and decompression-bomb coverage
- Track remaining work (CSP unsafe-inline removal) in plan.md
Co-Authored-By: Claude Fable 5 <[email protected]>
- Verify CSRF on POST /admin/uploads/resize (was the only state-changing
admin route without a check) and cap its body at 1 MB
- limitBody: exact-match /admin/upload and /admin/upload-file instead of
a prefix match that also exempted /admin/uploads/{delete,resize}
- Only honour X-Forwarded-Proto behind a trusted proxy (same rule as
X-Forwarded-For); fall back to the configured base_url scheme for the
session cookie Secure flag and baseURL()
- handleAdminBinSave: return 500 on non-ErrNoRows DB error instead of
dereferencing a nil paste
Co-Authored-By: Claude Fable 5 <[email protected]>
Sessions were stored in an in-memory map, so every server reboot logged the
admin out. Back the session store with the database instead:
- Add a sessions table (token, expires_at, created_at) created via the existing
migrate() (CREATE TABLE IF NOT EXISTS), backwards-compatible with deployed DBs.
- Add CreateSession / SessionValid / DeleteSession / CleanupSessions; expiry is
checked in SQL against datetime('now') (UTC).
- sessionStore is now a thin DB-backed wrapper with the same Create/Valid/Delete
interface; the hourly cleanup goroutine purges expired rows (plus once at
startup). Login, logout, requireAuth, and isLoggedIn are unchanged.
The session cookie was already persistent (MaxAge), so logins now survive both
browser and server restarts until session_hours expiry.
Co-Authored-By: Claude Opus 4.8 <[email protected]>