Skip to content

[Security] Validate JWT/auth-token in middleware.ts (currently only checks cookie existence) #652

Description

@nanaf6203-bit

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions