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

How JWT Signing Secrets get exposed

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

  1. Generate a new high-entropy secret — for example openssl rand -base64 48 — don't reuse or hand-type it.
  2. 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.
  3. 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.
  4. 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.
  5. Also invalidate refresh tokens / server-side sessions so an attacker can't quietly mint a new access token from a stale refresh token.
  6. 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

Keep your app safe