mass-assignment
A model's attributes set from a request without a list that leaves out privileges.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule mass-assignment - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
permit! lets a request set every attribute of the model it builds, including ones the form never shows, such as admin or role, and a permit list that names admin or role lets a request grant itself that privilege. List the attributes a request may set with permit(:name, :email), and set privileges in code that checks who may grant them.
The fix, as Ur suggests it: list the attributes with permit.
For agents
Never call permit!; list the attributes a request may set with permit.
Example
app/controllers/users_controller.rbclass UsersController < ApplicationController
def create
@user = User.new(user_params)
@user.save
end
private
def user_params
params.require(:user).permit!
end
end
$ ur scan --rule mass-assignment
warning[mass-assignment]: `permit!`, every parameter of the request, reaches `new`
--> ./app/controllers/users_controller.rb:3:13 method `create`
= step 1: ./app/controllers/users_controller.rb:10:5 `permit!`, every parameter of the request,
= step 2: ./app/controllers/users_controller.rb:3:22 `user_params` returns it
= hint: list the attributes with permit
= see: ActionController::Parameters#permit!, Ruby on Rails API (2025-10-01), https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-permit-21
scanned 1 file (no framework recognized)
mass-assignment: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
ActionController::Parameters#permit!, Ruby on Rails API (2025-10-01).