Leakage of hard-coded secret in JWT
- Rule ID: javascript_lang_jwt_hardcoded_secret
- Languages: javascript
- Source: jwt_hardcoded_secret.yml
Description
Storing hard-coded secrets in your code, especially for JSON Web Tokens (JWT), poses a significant security risk. This practice makes your application vulnerable to unauthorized access and attacks.
Remediations
- Do not hard-code secrets in your code. Hard-coding makes sensitive information easily accessible to anyone who can view the code.
- Do use environment variables to store sensitive information such as secrets. This method keeps credentials out of your codebase and makes them easier to manage securely.
var jwt = require("jsonwebtoken");
var token = jwt.sign({ foo: "bar" }, process.env.JWT_SECRET);
- Do consider implementing a key-management system to securely handle secrets and other sensitive information. This approach provides enhanced security measures for managing and accessing credentials.
References
Associated CWE
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=javascript_lang_jwt_hardcoded_secret
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=javascript_lang_jwt_hardcoded_secret