# WiseBet Nigeria — Security Test Report, Risk Assessment & Deployment Checklist

## 1. Automated Test Suite Coverage

The automated test suite consists of two comprehensive feature and security suites:
- `tests/Feature/WiseBetPlatformTest.php`
  - Public website pages (Home, Available Draws, Draw Details, How It Works, Winners Ledger, Contact, Terms, Privacy, Login, Register)
  - User registration, SHA-256 hashed email verification token validation, and Resend Welcome + Verification email dispatch
  - Login, logout session invalidation, and single-use time-limited password reset via Resend
  - Draw creation and Draw Agent permission verification
  - Ticket purchase initialization, rejection of unverified browser callbacks, HMAC-SHA512 Paystack webhook verification, idempotency under duplicate webhook replay, sequential `WB-2026-XXXXXX` numbering, and single/batch DomPDF generation
  - Public QR code verification (`/verify/WB-2026-XXXXXX`) for `Valid Ticket`, `Winning Ticket`, `Valid Ticket – Not a Winner`, `Refunded Ticket`, `Cancelled Ticket`, and `Ticket Not Found` with masked participant names and zero email leakage
  - Server-timed 14-day post-close countdown and automatic archiving without ticket deletion
  - CSPRNG (`random_int`) random winner selection, exclusion of refunded/cancelled tickets, prevention of duplicate winning tickets, prevention of re-running completed draws, halting/flagging when eligible tickets < configured winners, WhatsApp international click-to-chat URL generation, and end-to-end prize claim submission, agent review, admin approval, and payout recording
  - PWA manifest, service worker, offline read-only fallback, and IndexedDB snapshot endpoint
- `tests/Feature/WiseBetSecurityTest.php`
  - User data isolation and IDOR protection on single/batch ticket view, PDF, and print endpoints
  - Role-Based Access Control (RBAC) preventing privilege escalation and cross-agent draw modification
  - Forged Paystack webhook signature rejection (`401 Unauthorized`) and payment amount-manipulation rejection (`400 Bad Request`)
  - Brute-force login throttling and temporary account lockout (`locked_until`)
  - Immutability enforcement on finalised `DrawResult` and `Winner` records
  - Malicious executable file upload rejection (`.php` disguised as prize image) and HTTP security headers (`X-Frame-Options`, `X-Content-Type-Options`, `Referrer-Policy`, `Permissions-Policy`)

---

## 2. Security Risk Assessment & Residual Risk Disclosure

> **Important Security Disclosure**: No software platform should ever be described as "unhackable." Security is an ongoing operational discipline requiring layered defenses, continuous monitoring, dependency patching, and strict operational controls.

### Identified Risks, Mitigations Implemented & Operational Considerations

| Risk Area | Mitigation Implemented in WiseBet | Residual Operational Considerations |
|---|---|---|
| **Payment Webhook Forgery & Replay** | HMAC-SHA512 signature verification (`x-paystack-signature`), row-level `lockForUpdate()` transaction locking, and amount-in-kobo verification against the original order. | Rotate `PAYSTACK_SECRET_KEY` immediately if compromised; restrict webhook ingress at the WAF/Cloudflare layer to official Paystack IP ranges. |
| **CSPRNG & Draw Integrity** | Uses PHP's OS-backed `random_int()` in a partial Fisher-Yates shuffle without replacement; enforces model-level immutability (`DrawResult` & `Winner`) and unique database constraints. | Database server root/OS access could still tamper with raw storage if database access is not restricted; use managed MySQL with audit logging and restricted DBA privileges in production. |
| **IDOR & Broken Access Control** | Every participant ticket, transaction, and claim query is strictly scoped to `auth()->id()`; Agent queries are scoped to assigned draws (`draw_agents`); Admin routes enforce `role:super_admin`. | Conduct periodic penetration testing whenever new routes or API endpoints are added. |
| **Account Takeover & Brute-Force** | Rate limiting (`RateLimiter`), automatic 15-minute account lockout after 5 failed attempts, session regeneration on login, single-use hashed password reset tokens, and Super Admin 2FA. | Email-based 2FA depends on the security of the administrator's email account; enforce hardware MFA on all corporate `@wisebet.ng` mailboxes. |
| **Countdown Manipulation** | Backend archiving uses server timestamps (`closes_at + 14 days`); frontend countdown uses monotonic elapsed time (`performance.now()`) anchored to server-computed remaining seconds. | Ensure production server NTP clock synchronization (`chrony` / `systemd-timesyncd`) is active at all times. |
| **Shared Device PWA Cache Exposure** | IndexedDB stores only read-only non-sensitive ticket/draw summaries (never passwords, payment tokens, or bank account numbers) and clears user stores on logout. | Users on public cybercafé computers who close the browser without logging out leave their session active until expiry; keep `SESSION_LIFETIME` reasonable (e.g., 60–120 minutes). |

---

## 3. Production Deployment Checklist

- [ ] Set `APP_ENV=production` and `APP_DEBUG=false` in `.env`.
- [ ] Enforce HTTPS TLS 1.2/1.3 at Nginx/Cloudflare and set `SESSION_SECURE_COOKIE=true`.
- [ ] Configure production MySQL 8+ database with daily automated backups (`wisebet:backup-database` + off-site encrypted snapshots).
- [ ] Configure live `RESEND_API_KEY` with verified domain DNS records (SPF, DKIM, DMARC).
- [ ] Configure live `PAYSTACK_PUBLIC_KEY`, `PAYSTACK_SECRET_KEY`, and `PAYSTACK_WEBHOOK_SECRET`, and set `PAYSTACK_SANDBOX_MODE=false`.
- [ ] Enable Super Admin Two-Factor Authentication (`WISEBET_REQUIRE_ADMIN_2FA=true`) and rotate all seeded passwords.
- [ ] Configure Linux cron for `* * * * * php /path/to/artisan schedule:run` and Supervisor for `php artisan queue:work --tries=3`.
- [ ] Run `php artisan config:cache`, `php artisan route:cache`, and `php artisan view:cache`.

