Skip to content

ActiveRecord Encryption Misorder

Description

The declaration of the serialized attribute should go before the encryption declaration in ActiveRecord to ensure proper encryption of sensitive data.

Examples

Insecure Code

ruby
class User < ApplicationRecord
  encrypts :name
  serialize :name
end

Secure Code

ruby
class User < ApplicationRecord
  serialize :name
  encrypts :name
end

Remediation

Reorder the declarations to put the serialized attribute before the encryption declaration.

Rule Details

FieldValue
IDCODE-0241
CategoryCrypto
SeverityHIGH
CWECWE-311
ConfidenceHIGH
ImpactHIGH
LikelihoodHIGH
ExploitabilityMODERATE
Tagsencryption, serialization
OWASPN/A

References