You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using MyModel.find_by(params.permit(:foo_uid)) is flagged as a high-confidence SQL injection issue when it is one of a set of possible queries, based on conditional logic.
Full warning from Brakeman:
Confidence: High
Category: SQL Injection
Check: SQL
Message: Possible SQL injection
Code: MyModel.find_by((params.permit(:foo_uid) or { :id => params.require(:model_id) }))
In our use case, there are two different identifiers (one legacy) that can be sent in the params to identify the record and we wanted to streamline the logic and reduce duplication. However, this was flagged by Brakeman while the individual queries were not. It appears that when the arg.node_type is or, it doesn't use the list of allowable methods that are defined for a single request argument here. Instead, it eventually callshas_immediate_user_input? (via unsafe_sql? -> find_dangerous_value ) which marks it as an unsafe usage of params. Then unsafe_sql? calls safe_value?, which doesn't use the allow list either.
I'm not sure if params.permit should be marked as safe in all situations, but in this one - where the arglist passed to check_query_arguments is a set of possible options for the query - the outcome should be the same as if each option were individually evaluated.
The text was updated successfully, but these errors were encountered:
Background
Brakeman version: 6.1.2 through 7.0.2
Rails version: 7.1.5.1
Ruby version: 3.3.6
Issue
Using
MyModel.find_by(params.permit(:foo_uid))
is flagged as a high-confidence SQL injection issue when it is one of a set of possible queries, based on conditional logic.Full warning from Brakeman:
Relevant code with warning:
Equivalent code with no warning:
In our use case, there are two different identifiers (one legacy) that can be sent in the params to identify the record and we wanted to streamline the logic and reduce duplication. However, this was flagged by Brakeman while the individual queries were not. It appears that when the
arg.node_type
isor
, it doesn't use the list of allowable methods that are defined for a single request argument here. Instead, it eventually callshas_immediate_user_input?
(viaunsafe_sql?
->find_dangerous_value
) which marks it as an unsafe usage ofparams
. Thenunsafe_sql?
callssafe_value?
, which doesn't use the allow list either.I'm not sure if
params.permit
should be marked as safe in all situations, but in this one - where thearglist
passed tocheck_query_arguments
is a set of possible options for the query - the outcome should be the same as if each option were individually evaluated.The text was updated successfully, but these errors were encountered: