# Four critical pre-deployment checks

Checked on 17 November 2026 against the local checkout. **Deployment sign-off is on hold.**

| Protection | Code/test result | Live-site sign-off |
| --- | --- | --- |
| Backend Turnstile | PASS. Both exported registration POST handlers require successful Siteverify, hostname/action validation and an atomic shared token redemption. Direct requests with missing/invalid/expired/replayed tokens fail. Provider or replay-store failure denies registration. | Pending real production keys, migration and staging verification. |
| Login/OTP throttling | PASS. Shared atomic MySQL counters enforce IP/identifier/email budgets across workers; OTP guesses stop at five and resend waits at least sixty seconds. Storage failure denies requests. | Pending trusted Apache IP-header configuration and a shared production database. |
| Pending registration/access validation | PASS. Registration 201 means pending OTP verification and does not issue a session. Invalid/unverified/inactive users cannot obtain/use a session, including Google sign-in. Activation/OTP consumption and replay protections pass concurrency tests. | Pending deployed-build verification and normal staging signup/login tests. |
| Incident review: four login 200 / 41 registration 201 | NOT COMPLETE. Supplied counts and current code semantics reviewed. Raw production evidence was not available; affected accounts and session outcomes remain unknown. The 28 reported OTP-verification 200 responses also require correlation. | OPEN. See `INCIDENT_INVESTIGATION.md`. |

## Additional CAPTCHA issue found and fixed during this check

Cloudflare documents that replay detection can briefly lag during concurrent/closely spaced validations. Provider validation alone therefore cannot guarantee immediate single-use at the application boundary. `lib/turnstileReplay.js` now claims the verified token's SHA-256 hash using a unique MySQL key shared by all workers before protected processing proceeds. Concurrent submissions using one valid token have exactly one winner. Tokens are retained for ten minutes, exceeding their five-minute lifetime. [Cloudflare's server-side validation documentation](https://developers.cloudflare.com/turnstile/get-started/server-side-validation/).

The application calls Siteverify directly and uses MySQL. These protections do not require Redis, Cloudflare CDN/DNS proxying or a paid WAF subscription. The existing Apache reverse proxy can provide the trusted client-IP header once configured correctly. No live Apache/GCP settings or the separate sales app were changed.

## Validation

- `npm run security:test`: passed, including both direct registration handlers with mocked provider/email/database boundaries.
- `npm run security:test:mysql`: passed in a temporary local-only schema, including 24 simultaneous CAPTCHA redemptions across two worker instances with exactly one winner.
- `node scripts/test-auth-incident-review.mjs`: passed synthetic log fixtures. These are tests, not the real incident evidence.
- Targeted ESLint passed. The updated production build passed, including all 702 generated pages; the validation build did not deploy the application.
- Live deployment configuration remains incomplete in this checkout: real Turnstile keys, trusted ingress IP header and HTTPS public URL need setup. Do not replace the real deployment values with local defaults.

## Before sign-off

1. Apply both `scripts/migrations/20261117_auth_rate_limits.sql` and `scripts/migrations/20261117_turnstile_replay.sql` to the database used by all website workers. The CAPTCHA migration includes a rollback statement to use only after reverting the dependent application code.
2. Set real Turnstile keys and hostname/action configuration, the production HTTPS URL and a trusted Apache-overwritten client-IP header. Ensure the Next.js website port 3005 is not directly public. Run `npm run security:check` in the actual deployment environment.
3. Test valid signup, rejected direct signup without CAPTCHA, reused CAPTCHA, throttled login/OTP, verified login and Google behavior on staging.
4. Obtain and review the incident-time Apache/PM2 logs, deployed handler/build and read-only `newcw` evidence. Complete per-event account/session attribution and review the 28 OTP-verification responses.

No production deployment has been performed or approved by this check.
