unsafe-deserialization
Untrusted input loaded as Ruby objects.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule unsafe-deserialization - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
A value from a request is loaded with Marshal.load, YAML.load, or a loader like them, which can build any object and run code as it does. Load untrusted data with JSON.parse or YAML.safe_load.
The fix, as Ur suggests it: load it with JSON.parse or YAML.safe_load.
For agents
Never load untrusted data with Marshal or YAML.load; use JSON.parse or YAML.safe_load.
Example
app/controllers/password_resets_controller.rbclass PasswordResetsController < ApplicationController
def update
user = Marshal.load(Base64.decode64(params[:user]))
user.update(password: params[:password])
end
end
$ ur scan --rule unsafe-deserialization
warning[unsafe-deserialization]: `params`, a request parameter, reaches `Marshal.load`
--> ./app/controllers/password_resets_controller.rb:3:12 method `update`
= step 1: ./app/controllers/password_resets_controller.rb:3:41 `params`, a request parameter,
= step 2: ./app/controllers/password_resets_controller.rb:3:25 `.decode64` gives it
= hint: load it with JSON.parse or YAML.safe_load
= see: Marshal: Security considerations, Ruby 3.4 documentation (2024-12-25), https://docs.ruby-lang.org/en/3.4/marshal_rdoc.html#label-Security+considerations
scanned 1 file (no framework recognized)
unsafe-deserialization: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
Marshal: Security considerations, Ruby 3.4 documentation (2024-12-25).