Primary finding
Opt-in route 500s if OPTIN_HMAC_SECRET is missing (no graceful handling)
- apps/web/lib/optin-token.ts:1-200
- apps/web/app/api/opt-in/route.ts:1-200
verifyTokenDetailed() calls getSecret(), which throws if OPTIN_HMAC_SECRET is unset. handleOptIn() calls verifyTokenDetailed() without try/catch, so the request will crash with a 500 and no targeted error/log context. This is a server misconfiguration path that should be handled gracefully to aid operations and avoid noisy 5xx.
Recommendation
- In the route, guard the token verification with a try/catch that logs a clear server-misconfig event and returns a 500 with a generic error page. - Alternatively, validate OPTIN_HMAC_SECRET at module init of the route (or app startup) and fail fast with a clear boot-time error, preventing the app from serving until the secret is present. - Example: at top-level of route.ts, read process.env.OPTIN_HMAC_SECRET and if missing, log and export a GET that returns a 500 error page with a friendly message (no details about secrets). - Consider adding a healthcheck that asserts required env vars are present.