Problem Statement
src/middleware.ts and middleware.ts (root) check the existence of an auth-token cookie but never validate its cryptographic signature or expiry. Any user can craft a cookie named auth-token with arbitrary content and bypass the protected-route redirect logic for /dashboard, /portfolio, /settings, /invest.
Why It Matters
This is a textbook authentication bypass. Wallet-protected routes exposed by mistake would leak portfolio / KYC / referral information. Even when those pages are wallet-gated client-side, middleware-level authz is critical defence-in-depth.
Acceptance Criteria
- Middleware verifies the token signature via
jose.verifyJwt (or next-auth/jwt)
- Expiry (
exp) checked and 401 returned on expired tokens
- Clock skew tolerance is bounded
- Unit tests cover signed/expired/tampered/missing tokens
- Routes enforce even if a session is started client-side via wallet
Implementation Notes
Adopt @auth/core or iron-session patterns. Generate a key via openssl rand -hex 32 and store it as AUTH_SECRET in .env. Co-sign with the wallet nonce for cross-check.
Files Likely Affected
middleware.ts
src/middleware.ts
src/hooks/useAuth.ts
.env.schema (new)
Difficulty / Effort
- Difficulty: Hard
- Effort: T-Shirt L
Labels
security, priority:critical
Problem Statement
src/middleware.tsandmiddleware.ts(root) check the existence of anauth-tokencookie but never validate its cryptographic signature or expiry. Any user can craft a cookie namedauth-tokenwith arbitrary content and bypass the protected-route redirect logic for/dashboard,/portfolio,/settings,/invest.Why It Matters
This is a textbook authentication bypass. Wallet-protected routes exposed by mistake would leak portfolio / KYC / referral information. Even when those pages are wallet-gated client-side, middleware-level authz is critical defence-in-depth.
Acceptance Criteria
jose.verifyJwt(ornext-auth/jwt)exp) checked and 401 returned on expired tokensImplementation Notes
Adopt
@auth/coreor iron-session patterns. Generate a key viaopenssl rand -hex 32and store it asAUTH_SECRETin.env. Co-sign with the wallet nonce for cross-check.Files Likely Affected
middleware.tssrc/middleware.tssrc/hooks/useAuth.ts.env.schema(new)Difficulty / Effort
Labels
security,priority:critical