HS256 signing secret
Exposed JWT Signing Secret? Here's how to detect and rotate it
With your HS256 JWT secret an attacker can forge valid tokens and log in as any user or admin. Scan free with Trust, then roll the secret and invalidate old sessions.
A JWT signing secret is the shared key your backend uses to sign and verify JSON Web Tokens with an algorithm like HS256. Your server trusts any token that verifies against this secret. If the secret leaks, an attacker can mint their own tokens that look completely legitimate — so it's effectively the password to your entire auth system.
What an attacker can do with a leaked JWT Signing Secret
- Forges a valid token for any user ID and logs in as them — no password needed.
- Sets role or admin claims to true in a self-signed token and gains full admin access.
- Bypasses your login flow entirely, since any forged token verifies against the leaked secret.
- Keeps quiet access as long as the secret stays live — forged tokens are indistinguishable from real ones.
How JWT Signing Secrets get exposed
- Hardcoded as a fallback default (JWT_SECRET || 'dev-secret') that ships to production.
- Committed to a repo in a .env file or a config that got pushed public.
- Exposed in a client-side bundle or an API response because it was wired to the wrong env var.
- Printed to logs or an error tracker, or pasted into a chat while debugging auth.
Scan your repo and live site for exposed JWT Signing Secrets — free
Trust checks your code, git history, and shipped JavaScript. No signup, results in about a minute.
Run a free scan →How to rotate a leaked JWT Signing Secret
- Generate a new high-entropy secret — for example openssl rand -base64 48 — don't reuse or hand-type it.
- Roll it into your server env/secrets (Vercel, Railway, your host) as the JWT signing secret, then redeploy so the app signs new tokens with it.
- Understand that changing the secret invalidates every existing JWT — all current users get logged out and must sign in again, which is the point: it kills any forged tokens too.
- To avoid a mass-logout, use a key-rotation scheme — add a kid (key ID) header and accept both old and new secrets for a short overlap window, then drop the old secret once tokens expire.
- Also invalidate refresh tokens / server-side sessions so an attacker can't quietly mint a new access token from a stale refresh token.
- Audit your auth and access logs for suspicious token use — logins from unfamiliar IPs, privilege jumps, or activity on accounts that shouldn't be active — during the window the secret was exposed.
Other secret types to check
- AWS Access KeyAKIA…
- Stripe Secret Keysk_live_…
- OpenAI API Keysk-…
- Anthropic API Keysk-ant-api03-…
- Supabase Service-Role KeyeyJ… (JWT)
- GitHub Personal Access Tokenghp_… (also github_pat_…)