CRITICAL
Rule Definition
JWT secret keys should not be stored in the source code but in a secure environment. Indeed, if a user is able to access to the source code, he will be able to create JWTs accepted by the application.
Remediation
Do not store JWT secret keys in the source code.
Violation Code Sample
String base64Secret = "OWZhYzExODNmZGMxZjVlOTdmZDdiYzgxYTM3NWZmMTI=";
byte[] keyBytes = Decoders.BASE64.decode(base64Secret);
Key key = Keys.hmacShaKeyFor(keyBytes);
Fixed Code Sample
String jwtSecretKeyBase64 = System.getenv("jwt_secret_key_64");
byte[] keyBytes = Decoders.BASE64.decode(jwtSecretKeyBase64);
Key key = Keys.hmacShaKeyFor(keyBytes);
Reference
CWE-798: Use of hard-coded credentials
https://cwe.mitre.org/data/definitions/798.html
Related Technologies
Technical Criterion
CWE-798 - Use of Hard-coded Credentials
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.