Commit Graph
5 Commits
Author SHA1 Message Date
lucioandClaude Fable 5 82fb5122f3 Harden image decoding, shutdown, and CSRF cookie; add handler tests
- 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]>
2026-06-09 19:57:40 -07:00
lucioandClaude Fable 5 962f5d9e06 Fix security issues found in review
- 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]>
2026-06-09 19:43:32 -07:00
lucioandClaude Opus 4.8 67731cfcac Persist sessions in SQLite so logins survive a server restart
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]>
2026-06-05 01:08:25 -07:00
lucio 2f5c31499d security review 2026-06-02 01:24:19 -07:00
lucioandClaude Sonnet 4.6 60a09fa878 Initial commit: URL shortener + pastebin with dark admin UI and deploy scripts
Features:
- URL shortener with QR codes, click tracking, deduplication, rate limiting
- Pastebin with Markdown rendering, access tokens, raw view
- Admin dashboard: dark theme, stats bar, Quick Links tiles with favicons,
  card-based layout, format/token badges, empty states
- CSRF protection, bcrypt auth, in-memory sessions, security headers
- Pure-Go SQLite (no CGo), single self-contained binary

Deploy:
- deploy/install.sh: auto-detects systemd vs SysV init
- deploy/urlshort.service: hardened systemd unit
- deploy/urlshort.init: SysV init script for older Ubuntu

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-04-02 03:00:08 -07:00