# Security Checklist

## Implemented Security Measures

### Authentication & Sessions
- [x] Passwords hashed with bcrypt (cost 12)
- [x] Session regeneration on login (`session_regenerate_id(true)`)
- [x] Secure session cookie settings (httponly, samesite)
- [x] Session destruction on logout (cookie cleared)
- [x] Per-user login attempt tracking with account lockout (5 attempts → 15 min lock)
- [x] IP-based rate limiting (20 attempts per 15 minutes from same IP)

### Input Validation & Output Encoding
- [x] CSRF tokens on all POST forms (`csrf_field()` + `verify_csrf()`)
- [x] Output escaping via `e()` helper (htmlspecialchars)
- [x] Server-side validation on all form inputs
- [x] Email validation with `FILTER_VALIDATE_EMAIL`
- [x] Length limits on all text inputs
- [x] PDO prepared statements for all database queries (no raw interpolation)

### Authorization
- [x] Role-based access control (admin, manager, subscriber)
- [x] AuthMiddleware checks on every protected route
- [x] `require_auth()` and `require_role()` guards in controllers
- [x] Subscriber status checks (pending/rejected/suspended users blocked)

### File Upload Security
- [x] File type validation (allowed extensions whitelist)
- [x] File size limits
- [x] Uploaded files stored outside web-accessible PHP execution
- [x] Filename sanitization

### Directory Protection
- [x] `.htaccess` with `Deny from all` on sensitive directories:
  - `app/` — Application code
  - `config/` — Configuration with credentials
  - `database/` — Migration files
  - `routes/` — Route definitions
  - `lib/` — Third-party libraries
  - `cron/` — Scheduled tasks

### Error Handling
- [x] Debug mode toggle (`app.debug` in config)
- [x] Production: errors logged, user sees generic 500 page
- [x] Development: full error display for debugging
- [x] Try/catch wrapping in front controller
- [x] Custom error pages (403, 404, 500)

### SEO & Web Security
- [x] Canonical URLs to prevent duplicate content
- [x] robots.txt blocking admin/dashboard/cron paths

## Production Deployment Checklist

Before going live, verify:

- [ ] `config.php`: `debug` set to `false`
- [ ] `config.php`: `session.secure` set to `true` (with HTTPS)
- [ ] `config.php`: database password is strong
- [ ] SSL/TLS certificate installed and HTTPS forced
- [ ] Default admin password changed
- [ ] `robots.txt` Sitemap URL updated to production domain
- [ ] `.htaccess` files present in all sensitive directories
- [ ] `public/uploads/` directory has correct permissions (755, not 777)
- [ ] PHP `display_errors` is OFF in production php.ini
- [ ] Database user has minimum required privileges (not root)
- [ ] SMTP credentials are valid and tested
- [ ] Cron job is configured and running
