From 422aec5b3a6393304f4565bb98cfa8b7e4dd5190 Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Tue, 10 Oct 2023 22:42:56 -0700 Subject: [PATCH] Fix kwsplats in filter options Fixes #1790 --- lib/brakeman/tracker/controller.rb | 24 +++++++++++-------- .../app/controllers/admin_controller.rb | 5 ++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/brakeman/tracker/controller.rb b/lib/brakeman/tracker/controller.rb index 5fee879000..61ddd0361d 100644 --- a/lib/brakeman/tracker/controller.rb +++ b/lib/brakeman/tracker/controller.rb @@ -120,16 +120,20 @@ def before_filter_to_hash processor, args filter[:methods] << a[1] if a.node_type == :lit end - if args[-1].node_type == :hash - option = args[-1][1][1] - value = args[-1][2] - case value.node_type - when :array - filter[option] = value.sexp_body.map {|v| v[1] } - when :lit, :str - filter[option] = value[1] - else - Brakeman.debug "[Notice] Unknown before_filter value: #{option} => #{value}" + options = args.last + + if hash? options + # Probably only one option, + # but this also avoids issues with kwsplats + hash_iterate(options) do |option, value| + case value.node_type + when :array + filter[option.value] = value.sexp_body.map {|v| v[1] } + when :lit, :str + filter[option.value] = value[1] + else + Brakeman.debug "[Notice] Unknown before_filter value: #{option} => #{value}" + end end else filter[:all] = true diff --git a/test/apps/rails7/app/controllers/admin_controller.rb b/test/apps/rails7/app/controllers/admin_controller.rb index 747b2e1526..2fde80c107 100644 --- a/test/apps/rails7/app/controllers/admin_controller.rb +++ b/test/apps/rails7/app/controllers/admin_controller.rb @@ -3,4 +3,9 @@ def search_users # Medium warning because it's probably an admin interface User.ransack(params[:q]) end + + # Test kwsplats in filter options + before_filter(**options) do |c| + x + end end