Skip to content

Insecure Rails Cache Store Configuration

Description

The Rails cache store is configured to allow Marshaling, which can lead to code execution if an attacker can inject data into the cache store. This is because the default serializer in Rails 7.1 is `:marshal_7_1`. Consider using a custom serializer like JSON or MessagePack that does not fallback on Marshal.

Examples

Insecure Code

ruby
config.cache_store = :mem_cache_store

Secure Code

ruby
config.cache_store = :mem_cache_store, { serializer: :json }

Remediation

Configure the Rails cache store to use a custom serializer like JSON or MessagePack. For example, set `config.cache_store` to `:mem_cache_store` with a custom serializer: `config.cache_store = :mem_cache_store, { serializer: :json }`

Rule Details

FieldValue
IDCODE-0434
CategoryDeserialization
SeverityHIGH
CWECWE-502
ConfidenceMEDIUM
ImpactHIGH
LikelihoodLOW
ExploitabilityMODERATE
Tagscache, serialization, deserialization
OWASPN/A

References