Skip to main content
HighCodeOWASP A02:2021CWE-326

How to fix: HS256 signed with weak or hardcoded secret

jwt.sign(payload, 'secret') or jwt.sign(payload, process.env.JWT_SECRET) where JWT_SECRET is a short, low-entropy string enables offline brute-force of the HMAC key.

Why it matters

Attackers recover the HS256 secret and forge tokens for any identity, bypassing authentication entirely.

The `code-jwt-hs256-weak-secret` check verifies that the server does not expose the `jwt-hs256-weak-secret` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.

How to fix it

  1. 1Use a 256-bit (32-byte) random secret generated with crypto.randomBytes.
  2. 2Rotate secrets regularly and store them in a secret manager, not env files.
  3. 3Consider migrating to RS256 or EdDSA so verifiers only need the public key.

Code examples

Use a strong random secret for HS256

bash
# Generate a strong HS256 secret (256 bits = 32 bytes)
openssl rand -base64 32
# Store in environment: JWT_SECRET="the-output-above"
# Never use short or predictable secrets like "secret", "password", or < 32 chars

References

Detected automatically by VulnRadar. The check id is code-jwt-hs256-weak-secret, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is HS256 signed with weak or hardcoded secret?
VulnRadar rates this high severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-jwt-hs256-weak-secret, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does HS256 signed with weak or hardcoded secret map to?
It maps to CWE-326. In the OWASP Top 10 it falls under A02:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for hs256 signed with weak or hardcoded secret

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

HS256 signed with weak or hardcoded secret fix | VulnRadar