Usage of weak model specific encryption key

Description

Weak model-specific encryption keys can compromise data security. To ensure effective encryption, model-specific encryption keys should be 12 bytes or greater.

Remediations

  • Do not use model-specific encryption keys shorter than 12 bytes. Short keys are easier to crack, putting your data at risk.
    class User < ApplicationRecord
    encrypts :email, key: "weak-key" # unsafe
    end
  • Do ensure your model-specific encryption keys are 12 bytes or longer to maintain strong encryption and protect sensitive data.
    class User < ApplicationRecord
    encrypts :email, key: "stronger-key-example"
    end

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=ruby_rails_weak_custom_key

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

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