Skip to content

Commit ff2b01f

Browse files
maebealeclaude
andcommitted
Fix Brakeman SQL injection warnings by removing string interpolation in Arel.sql
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 27d037d commit ff2b01f

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

app/controllers/admin/ahoy_activities_controller.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def apply_event_sort(scope, column, direction)
176176
when "name"
177177
scope.reorder(name: dir)
178178
when "user"
179-
scope.left_joins(:user)
180-
.reorder(Arel.sql("users.first_name #{direction}, users.last_name #{direction}"))
179+
user_sort = { "asc" => "users.first_name ASC, users.last_name ASC",
180+
"desc" => "users.first_name DESC, users.last_name DESC" }
181+
scope.left_joins(:user).reorder(Arel.sql(user_sort[direction]))
181182
else
182183
scope.reorder(time: :desc)
183184
end
@@ -205,12 +206,13 @@ def apply_visit_sort(scope, column, direction)
205206
when "started_at"
206207
scope.reorder(started_at: dir)
207208
when "user"
208-
scope.left_joins(:user)
209-
.reorder(Arel.sql("users.first_name #{direction}, users.last_name #{direction}"))
209+
user_sort = { "asc" => "users.first_name ASC, users.last_name ASC",
210+
"desc" => "users.first_name DESC, users.last_name DESC" }
211+
scope.left_joins(:user).reorder(Arel.sql(user_sort[direction]))
210212
when "events_count"
211-
scope.reorder(Arel.sql("events_count #{direction}"))
213+
scope.reorder(Arel.sql(dir == :asc ? "events_count ASC" : "events_count DESC"))
212214
when "duration"
213-
scope.reorder(Arel.sql("duration_minutes #{direction}"))
215+
scope.reorder(Arel.sql(dir == :asc ? "duration_minutes ASC" : "duration_minutes DESC"))
214216
else
215217
scope.reorder(started_at: :desc)
216218
end

config/brakeman.ignore

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@
2323
],
2424
"note": ""
2525
},
26-
{
27-
"warning_type": "Remote Code Execution",
28-
"warning_code": 24,
29-
"fingerprint": "59ffdfd50cdef491cfd47d69eaa3edc1d3a291661c75c5f1b10c7afa173581af",
30-
"check_name": "UnsafeReflection",
31-
"message": "Unsafe reflection method `constantize` called on parameter value",
32-
"file": "app/controllers/api/v1/resources_controller.rb",
33-
"line": 3,
34-
"link": "https://brakemanscanner.org/docs/warning_types/remote_code_execution/",
35-
"code": "params[:type].constantize",
36-
"render_path": null,
37-
"location": {
38-
"type": "method",
39-
"class": "Api::V1::ResourcesController",
40-
"method": "index"
41-
},
42-
"user_input": "params[:type]",
43-
"confidence": "High",
44-
"cwe_id": [
45-
470
46-
],
47-
"note": ""
48-
},
4926
{
5027
"warning_type": "Mass Assignment",
5128
"warning_code": 70,

0 commit comments

Comments
 (0)