Skip to content
Access control Disclosed report Intermediate CVE-2020-8164

ActionController::Parameters .each returns an unsafe hash

Calling `.each` on an `ActionController::Parameters` object returns a plain Ruby hash containing every parameter, including ones that were never permitted. An attacker who knows a controller uses `.each` could slip extra parameters such as an admin flag past authorisation checks.

abuisman Follow

Originally disclosed on HackerOne

Medium 6.5 View original
  • Triaged in 2.5 years
  • Fixed in 2.5 years
  • Paid in 2.5 years
  • Disclosed after 2.5 years

Rails 5.1.4

The goal of ActionController::Parameters's permit method (strong parameters) is to prevent accidental trust in the parameters sent by the client. We can therefore not simply create a hash of all the parameters in the params without permitting them first. When we really want to do this there is the method to_unsafe_h, indicating the importance of controlling when an unsafe hash is returned. However, when we use .each on our parameters object, an unsafe hash is returned that includes all the keys and their values in a new hash:

Ruby
params = ActionController::Parameters.new(city: 'Nijmegen', country: 'Netherlands', language: 'Dutch')

params.to_h

# ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
# from ...lib/ruby/gems/2.4.0/gems/actionpack-5.1.4/lib/action_controller/metal/strong_parameters.rb:265:in `to_h'

params.permit(:city)
=> <ActionController::Parameters {"city"=>"Nijmegen"} permitted: true>

params.permit(:city).to_h
=> {"city"=>"Nijmegen"}

params.to_unsafe_h
=> {"city"=>"Nijmegen", "country"=>"Netherlands", "language"=>"Dutch"}

params.each {}
=> {"city"=>"Nijmegen", "country"=>"Netherlands", "language"=>"Dutch"}

This behaviour is extra strange when contraste with how select works:

Ruby
params.select { true }
=> <ActionController::Parameters {"city"=>"Nijmegen", "country"=>"Netherlands", "language"=>"Dutch"} permitted: false>

Here you can see that select returns an instance of ActionController::Parameters that has permitted: false

Impact

An attacker could find out about the accidental use of each in working with parameters in a controller and use this knowledge to send additional (more than provided in a form) parameters along and in this way circumvent authorisation checks.

Ruby
# controller:

def update
  # Attacker has included the parameter: `{ is_admin: true }`
  User.update(clean_up_params)
end

def clean_up_params
  
   params.each { |k, v|  SomeModel.check(v) if k == :name }
end

The example (admittedly simplified) above shows a possible scenario where a developer builds a method to do something with each param in a seperate method after which he might expect his parameters to adhere to normal working permitted: true/false. Slightly unexpected behaviour that could cause security issues.

Biggest threat would seem to be to opensource projects where attackers can survey the project's code.

The original report as published on HackerOne, by abuisman. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the `each` method on `ActionController::Parameters` returns a plain hash of all parameters instead of yielding from the parameters object itself, so the permitted/unpermitted tracking is lost.

Impact

An attacker could send extra parameters beyond those in a form and, where a controller relies on `.each`, potentially bypass authorisation checks; the author notes open-source projects are most exposed because their code can be reviewed.

What the attacker needed

Application code calls .each on params; attacker can read or guess that code

The fix

The report suggests .each should not return an unsafe hash of all parameters, preserving the permitted distinction.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

In Ruby on Rails, a controller receives form data as a special object that tracks which fields the developer has explicitly allowed ("permitted"). Normally you cannot turn that object into a plain hash unless you permit the fields first. The report shows that looping over it with `.each` quietly hands back a plain hash of everything, so fields the developer never allowed can reach the code that follows.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.