# Production Hardening Checklist — Bravo & ACC portals

Applies to **both** `Bravo-Maps/server` and `ACC-MAP PORTAL/server`. Work top-down;
the 🔴 items are release blockers. Nothing here changes application code — these are
deployment/config/credential steps that must be done ON THE SERVER, not on localhost.

---

## 🔴 1. Turn off debug + set the environment
In `.env`:
```
APP_ENV=production
APP_DEBUG=false
```
Why: with `APP_DEBUG=true` every error returns a full stack trace + absolute server
paths to the caller. `false` turns those into a generic `{"message":"Server Error"}`.
This single change neutralises the info-leaks found in the audit.

After changing, run once on the server:
```
php artisan config:cache
php artisan route:cache
php artisan event:cache
```
(Re-run these after ANY `.env` change — cached config ignores later edits.)

## 🔴 2. Dedicated database user (stop using root)
Currently `DB_USERNAME=root` with an empty `DB_PASSWORD`. Create a least-privilege user:
```sql
CREATE USER 'bravo_app'@'localhost' IDENTIFIED BY '<STRONG-UNIQUE-PW>';
GRANT SELECT, INSERT, UPDATE, DELETE ON bravo_maps.* TO 'bravo_app'@'localhost';
FLUSH PRIVILEGES;
```
(For ACC: user `acc_app`, database `acc_map_portal`.) Then in `.env`:
```
DB_USERNAME=bravo_app
DB_PASSWORD=<STRONG-UNIQUE-PW>
```
Keep DDL (CREATE/ALTER/DROP) OUT of the app user — run migrations with a separate
admin login during deploy only.

## 🔴 3. Strong, unique admin passwords
`bravo2027` is on multiple super-admins (incl. `admin@accbravo.com` / `admin@accbravo.ng`).
Reset every admin to a strong unique password:
```
php artisan tinker
>>> $u = App\Models\User::where('email','admin@accbravo.com')->first();
>>> $u->password = Hash::make('<STRONG-UNIQUE-PW>'); $u->save();
```
Delete or disable any leftover test accounts (`test@`, `scopetest@`, `noscope@`,
`incient@`, `agent@bravo.ng`) before go-live.

## 🔴 4. Rotate every shared secret
These were shared in chat and/or reused across both portals — rotate at the provider,
then update `.env`:
- **Twilio** — SID + auth token + from-number (token returned 401 already)
- **Pusher** — app secret (+ key/id if regenerated)
- **Google Maps/Geocode** key — and restrict it (HTTP referrer / IP + Geocoding API only)
- Use **different** secrets per portal; do not share one Pusher/Google key across Bravo and ACC.

## 🟠 5. Re-enable TLS verification (it's disabled for local certs)
In `.env` set all of these to `true` and use https:
```
PUSHER_SCHEME=https
PUSHER_VERIFY_SSL=true
GOOGLE_VERIFY_SSL=true
TWILIO_VERIFY_SSL=true
```
`false` allows man-in-the-middle on those API calls.

## 🟠 6. URLs, CORS, proxy, sessions
```
APP_URL=https://<api-domain>
FRONTEND_URL=https://<portal-domain>        # CORS is locked to this (good) — must be the real origin
TRUSTED_PROXIES=<load-balancer-ip or *>     # so Laravel sees real https scheme + client IP
SESSION_SECURE_COOKIE=true
SESSION_ENCRYPT=true
```

## 🟡 7. File permissions on the server (Linux)
```
chmod 600 storage/oauth-private.key storage/oauth-public.key
chown -R www-data:www-data storage bootstrap/cache
find storage -type d -exec chmod 750 {} \;
```
Passport keys are now in `.gitignore` (done in code). Regenerate per-environment with
`php artisan passport:keys` — do NOT copy the dev keys to production.

## 🟡 8. Web root + queue/scheduler
- Point the vhost docroot at `server/public` ONLY. Nothing above `public/` may be web-served
  (that would expose `.env`, `storage/`, keys).
- Live-sheet sync needs cron: `* * * * * php /path/artisan schedule:run >> /dev/null 2>&1`
  (the health gate warns "sync stale" until this runs).
- Set `PHP_CLI_BINARY` to the CLI php path so background imports spawn correctly under php-fpm.

## 🟡 9. HTTPS + headers (web server)
- Force HTTPS redirect; enable HSTS.
- The API is stateless (Bearer tokens) so no CSRF concern, but keep `X-Content-Type-Options: nosniff`
  and a restrictive `Referrer-Policy` at the proxy.

---

## ✅ Verified SECURE in the audit (no action needed)
- Auth required on every route except `POST /api/login`.
- State-scope IDOR: out-of-scope states return 403/404 (no leak).
- Privilege escalation: non-admins get 403 on all admin endpoints.
- SQL injection: parameterised + whitelisted (malicious params → clean 200).
- Stored XSS: not reachable (no user data in `dangerouslySetInnerHTML`; React escapes).
- Mass assignment: models use `$fillable`, no `->all()`.
- Command injection: none (static `nproc`; upload args escaped).
- External calls (Pusher/Twilio/Google/Sheets): all isolated with try/catch + timeouts.

## ✅ Fixed IN CODE during the audit (both portals)
- Login brute-force throttle (`throttle:5,1`) — verified returns 429 after 5 attempts.
- Import orphan batches: crash/early-return now marks the batch `failed` (was stuck "processing" forever).
- Division-by-zero in `StateController` state rate (a zero-register state 500'd its own summary).
- Passport keys added to `.gitignore`.
