Usage of hard-coded secret

Description

Storing secrets directly in your code is a security risk. Instead, opt for environment variables or a secret management system to safeguard your secrets.

Remediations

  • Do not store plaintext secrets in your code. This exposes sensitive information to unnecessary risk.
      passport.use(new OAuth2Strategy({
    authorizationURL: 'https://www.example.com/oauth2/authorize',
    tokenURL: 'https://www.example.com/oauth2/token',
    clientID: 'my-id-123',
    clientSecret: 'shh-my-secret',
    callbackURL: 'http://localhost:3000/auth/example/callback'
    },
    function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ exampleId: profile.id }, function (err, user) {
    return cb(err, user);
    });
    }
    ));
  • 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.
  • 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_hardcoded_secret

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=javascript_lang_hardcoded_secret