-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruby: Add query for insecure mass assignment #15987
Ruby: Add query for insecure mass assignment #15987
Conversation
aa936e2
to
a9f49ce
Compare
QHelp previews: ruby/ql/src/queries/security/cwe-915/MassAssignment.qhelpInsecure Mass AssignmentOperations that allow for mass assignment (setting multiple attributes of an object using a hash), such as RecommendationWhen using a mass assignment operation from user supplied parameters, use ExampleIn the following example, class UserController < ActionController::Base
def create
# BAD: arbitrary params are permitted to be used for this assignment
User.new(user_params).save!
end
def user_params
params.require(:user).permit!
end
end In the following example, only specific parameters are permitted, so the mass assignment is safe. class UserController < ActionController::Base
def create
# GOOD: the permitted parameters are explicitly specified
User.new(user_params).save!
end
def user_params
params.require(:user).permit(:name, :email)
end
end References
|
3d7c7ae
to
01f7124
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. I have only some minor comments. DCA shows a significant slowdown for one big Rails repo. I think it's worth running against the rails-projects
source suite to see if there's a pattern there that we need to look into.
I also noticed in the Rails guide that you can do
params.permit(preferences: {})
which allows arbitrary data inside preferences
. We should probably extend the query to cover that case, but that can be a follow-up and doesn't need to block this PR.
QHelp previews: ruby/ql/src/queries/security/cwe-915/MassAssignment.qhelperrors/warnings:
|
31adf40
to
9fa0bad
Compare
QHelp previews: ruby/ql/src/queries/security/cwe-915/MassAssignment.qhelpInsecure Mass AssignmentOperations that allow for mass assignment (setting multiple attributes of an object using a hash), such as RecommendationWhen using a mass assignment operation from user supplied parameters, use ExampleIn the following example, class UserController < ActionController::Base
def create
# BAD: arbitrary params are permitted to be used for this assignment
User.new(user_params).save!
end
def user_params
params.require(:user).permit!
end
end In the following example, only specific parameters are permitted, so the mass assignment is safe. class UserController < ActionController::Base
def create
# GOOD: the permitted parameters are explicitly specified
User.new(user_params).save!
end
def user_params
params.require(:user).permit(:name, :email)
end
end References
|
9fa0bad
to
fb19288
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I came looking out of curiosity, looks great, but I'll defer to @hmac's review. Just a few drive-by comments
@@ -52,4 +53,45 @@ module MassAssignment { | |||
result.(DataFlow::PostUpdateNode).getPreUpdateNode() = this.getParamsArgument() | |||
} | |||
} | |||
|
|||
/** Holds if `h` is an empty hash or contains an empty hash at one if its (possibly nested) values. */ | |||
private predicate hasEmptyHash(Expr e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use CFG nodes instead of AST nodes here. I.e., use HashLiteralCfgNode
instead of HashLiteral
, etc.
This query looks for instances of request parameters having
permit!
called on them, which allows arbitrary parameters to be specified by the request, and then being used for a mass assignment operation.