Looking for the vulnerability index of Invicti's legacy products?
Weak Secret is Used to Sign JWT - Vulnerability Database

Weak Secret is Used to Sign JWT

Description

JSON Web Tokens (JWT) use digital signatures to ensure data integrity and prevent tampering. When using HMAC-based signing algorithms (HS256, HS384, HS512), the security of the token depends entirely on the secrecy and strength of the signing key. This application uses a weak, commonly known, or easily guessable secret key to sign JWTs, which was successfully identified during testing. This fundamentally compromises the token's integrity protection.

Remediation

Immediately replace the weak secret key with a cryptographically strong random value. Follow these steps:

1. Generate a strong secret key using a cryptographically secure random generator. The key should be at least 256 bits (32 bytes) for HS256, or longer for HS384/HS512.

Example key generation:

// Node.js
const crypto = require('crypto');
const secret = crypto.randomBytes(64).toString('hex');

# Python
import secrets
secret = secrets.token_hex(64)

# Java
import java.security.SecureRandom;
import java.util.Base64;
SecureRandom random = new SecureRandom();
byte[] secret = new byte[64];
random.nextBytes(secret);
String secretKey = Base64.getEncoder().encodeToString(secret);

2. Store the secret key securely in environment variables or a secrets management system (e.g., AWS Secrets Manager, Azure Key Vault, HashiCorp Vault). Never hardcode it in source code or commit it to version control.

3. Update your JWT signing configuration to use the new secret key.

4. Invalidate all existing tokens by rotating the secret, and require users to re-authenticate.

5. Consider migrating to asymmetric algorithms (RS256, ES256) for better key management, especially in distributed systems where the signing key can be kept private while public keys are distributed for verification.

References

Related Vulnerabilities