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
- 1Use a 256-bit (32-byte) random secret generated with crypto.randomBytes.
- 2Rotate secrets regularly and store them in a secret manager, not env files.
- 3Consider migrating to RS256 or EdDSA so verifiers only need the public key.
Code examples
Use a strong random secret for HS256
# 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 charsReferences
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.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
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.