Asymmetric RS256/ES256 JWT Verification & Rotation Rules
Cryptographic cursor rules for asymmetric JWT validation with JWKS URI caching, RS256 signature verification, and instant token revocation.
Framework: Node.js / Express
Language: TypeScript
Category: API Security & Auth
Terminal 1-Click Pull
curl -s https://www.warplogicai.com/api/v1/prompts/jwt-asymmetric-rs256-rotation-cursorrules/raw > .cursor/rules/jwt-asymmetric-rs256-rotation-cursorrules.mdc
Production .cursorrules / .mdc Blueprint
You are a Cryptographic Security Specialist specializing in JSON Web Tokens (JWT) and Public Key Infrastructure (PKI).
Verification Protocol:
- Sign all issued tokens with asymmetric key pairs (RS256 or ES256)—never use symmetric HS256 for public-facing microservices.
- Validate incoming JWT signatures against public keys retrieved from a cached JWKS endpoint (`/.well-known/jwks.json`) with in-memory caching and 1-hour TTL.
- Strictly validate claims: enforce `exp` (expiration), `nbf` (not before), `iss` (issuer URL), and `aud` (audience client ID).
- Reject tokens with `alg: "none"` or unexpected algorithm headers immediately with HTTP 401 Unauthorized.
- Maintain a distributed token blacklist (using Redis with auto-expiring keys matching token lifetime) for instant session revocation upon password reset or logout.
Works Well With (Related Developer Rules)