recordselect 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9004f2682a4156b93ecbadc269e53a2c8c1c7b03ca2f22b80f0ff40e727e3c69
4
- data.tar.gz: 1e33c470ca134cd5338025144408eeea80650969b3a321308428b6405f142016
3
+ metadata.gz: cc39c84fde64efd9594dd1dac16025a735a1cb831d0cf3f66c9bf3e66ee0e3cf
4
+ data.tar.gz: 51a9f5dca54cc08d17adc61a97758c32d4f30ba5a214ec46f8632ff78be6c32f
5
5
  SHA512:
6
- metadata.gz: a43027fd27673c1a0887c334dbba2448fad6590c440bed5496873b8449a130e1fbb77ad54f68c94721fc096e4d661bff0fa0a4203cacaacb1ed40d2fe4f05e65
7
- data.tar.gz: 243ea04d2e3b29a937f3cea800743fa2e0cbf5257d3f7147aa6bf8b30ed4eb9f6a604a9f4c1b5dcd162db237d265dca7911f9855106ed6e2f0efd95c9b6c64ce
6
+ metadata.gz: bd22d4ef8358948db8a83a856d4433c210ec3bfe5b2ad3fdc6ca5862ff7ebe4d6ce8d7fe43056a59a84f34f5fee807777e4de93dc7d3edf6d509444addab560f
7
+ data.tar.gz: dd8f3723ba5ca227eec3115099a3bb31c62edac3b19c460c513e7e716811e940984e6f886a0bf592ec281f50f3032e8d117e1c866ef8738d0ce26aa4f40d0254
data/README CHANGED
@@ -68,7 +68,23 @@ Override either default for a controller:
68
68
  record_select search_on: [:name], allowed_columns: [:company_id, :active], excluded_columns: [:active]
69
69
  ```
70
70
 
71
- Exclusions take precedence over allowed columns. Symbols and strings are accepted. In 4.1.1, both settings default to +nil+, preserving filtering on all model columns with a deprecation warning when a column filter is used. The warning is emitted on every request that applies automatic URL column filters. In 4.2.0, +allowed_columns+ will default to +[]+, disabling automatic URL column filtering. An empty allowed list disables all automatic URL column filters. Controller options replace the corresponding global list; explicit +allowed_columns: nil+ allows all model columns and +excluded_columns: []+ clears global exclusions for that controller. To explicitly retain unrestricted filtering without a warning, set +allowed_columns: nil, excluded_columns: []+ (or the corresponding global settings). These settings do not restrict the trusted SQL expressions in +search_on+ or custom controller conditions.
71
+ Exclusions take precedence over allowed columns. Symbols and strings are accepted. +allowed_columns+ defaults to +[]+, disabling automatic URL column filters. +excluded_columns+ defaults to +nil+ and must be explicitly configured globally or per controller; otherwise +record_select+ raises +ArgumentError+ when the controller is loaded. With eager loading this normally happens at boot; with lazy loading it may happen on the first request to that controller.
72
+
73
+ To acknowledge disabled URL column filtering globally:
74
+
75
+ ```rb
76
+ RecordSelect.excluded_columns = []
77
+ ```
78
+
79
+ To enable only specific filters for a controller:
80
+
81
+ ```rb
82
+ record_select search_on: [:name], allowed_columns: [:company_id], excluded_columns: []
83
+ ```
84
+
85
+ To explicitly restore unrestricted legacy filtering, use +allowed_columns: nil, excluded_columns: []+ (or the corresponding global settings). This permits filtering on hidden model columns and restores the reported disclosure risk. Prefer a narrow allowlist.
86
+
87
+ Controller options replace the corresponding global list. These settings do not restrict the trusted SQL expressions in +search_on+ or custom controller conditions.
72
88
 
73
89
  = CALLBACKS
74
90
 
@@ -76,7 +76,6 @@ module RecordSelect
76
76
 
77
77
  conditions << record_select_condition_for_column(column, value)
78
78
  end
79
- record_select_config.warn_unconfigured_column_filters unless conditions.empty?
80
79
  conditions
81
80
  end
82
81
 
@@ -12,8 +12,14 @@ module RecordSelect
12
12
  @search_on = [options[:search_on]].flatten
13
13
  allowed_columns = options.fetch(:allowed_columns) { RecordSelect.allowed_columns }
14
14
  excluded_columns = options.fetch(:excluded_columns) { RecordSelect.excluded_columns }
15
+ if excluded_columns.nil?
16
+ raise ArgumentError, 'record_select requires explicit :excluded_columns (use [] for no exclusions). ' \
17
+ 'URL column filters are disabled by default; set :allowed_columns to the required columns. ' \
18
+ 'To explicitly restore unrestricted legacy filtering, use allowed_columns: nil, excluded_columns: []. ' \
19
+ 'This is unsafe: filtering on hidden model columns can disclose sensitive values. Prefer an explicit allowlist.'
20
+ end
15
21
  @allowed_columns = Array(allowed_columns).map(&:to_s) unless allowed_columns.nil?
16
- @excluded_columns = Array(excluded_columns).map(&:to_s) unless excluded_columns.nil?
22
+ @excluded_columns = Array(excluded_columns).map(&:to_s)
17
23
  @order_by = options[:order_by]
18
24
  @full_text_search = options[:full_text_search]
19
25
  @label = options[:label]
@@ -50,21 +56,10 @@ module RecordSelect
50
56
  # NOTE: this does *NO* default transforms (such as LOWER()), that's left entirely up to you.
51
57
  attr_reader :search_on
52
58
 
53
- def warn_unconfigured_column_filters
54
- return unless allowed_columns.nil? && excluded_columns.nil?
55
-
56
- RecordSelect.deprecator.warn(
57
- "Automatic URL filtering on all model columns is deprecated and can expose hidden values. " \
58
- "Configure allowed_columns to list permitted filter columns, or [] to disable URL column filtering. " \
59
- "Set allowed_columns: nil and excluded_columns: [] to explicitly retain unrestricted filtering " \
60
- "without this warning. Automatic URL column filtering will be disabled by default in RecordSelect 4.2.0."
61
- )
62
- end
63
-
64
59
  def column_allowed?(name)
65
60
  name = name.to_s
66
61
  allowed = allowed_columns
67
- (allowed.nil? || allowed.include?(name)) && (excluded_columns.nil? || !excluded_columns.include?(name))
62
+ (allowed.nil? || allowed.include?(name)) && !excluded_columns.include?(name)
68
63
  end
69
64
 
70
65
  def order_by
@@ -4,7 +4,7 @@ module RecordSelect
4
4
  module Version
5
5
  MAJOR = 4
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 2
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
data/lib/record_select.rb CHANGED
@@ -6,7 +6,7 @@ module RecordSelect
6
6
  class << self
7
7
  attr_accessor :allowed_columns, :excluded_columns
8
8
  end
9
- self.allowed_columns = nil
9
+ self.allowed_columns = []
10
10
  self.excluded_columns = nil
11
11
 
12
12
  def self.deprecator
@@ -105,52 +105,34 @@ class RecordSelectConfigurationTest < ActiveSupport::TestCase
105
105
  assert_equal [], controller(allowed_columns: []).filters
106
106
  end
107
107
 
108
- def test_defaults_leave_both_column_policies_unconfigured
109
- assert_nil @allowed_columns
108
+ def test_default_policy_requires_explicit_exclusions
109
+ assert_equal [], @allowed_columns
110
110
  assert_nil @excluded_columns
111
- RecordSelect.excluded_columns = nil
112
- assert_nil config.allowed_columns
113
- assert_nil config.excluded_columns
114
- end
111
+ RecordSelect.allowed_columns = @allowed_columns
112
+ RecordSelect.excluded_columns = @excluded_columns
115
113
 
116
- def test_explicit_nil_exclusions_override_global_exclusions_and_warn
117
- RecordSelect.excluded_columns = [:password_digest]
118
- instance = controller(excluded_columns: nil)
119
- warnings = capture_filter_warnings { assert_equal 3, instance.filters.length }
120
- assert_equal 1, warnings.length
114
+ error = assert_raise(ArgumentError) { config }
115
+ assert_match(/requires explicit :excluded_columns/, error.message)
116
+ assert_match(/unsafe.*hidden model columns/, error.message)
117
+ assert_match(/allowed_columns/, error.message)
118
+ assert_equal [], controller(excluded_columns: []).filters
121
119
  end
122
120
 
123
- def test_unconfigured_filters_warn_each_time_filters_are_built
121
+ def test_allowlist_does_not_bypass_required_exclusions
124
122
  RecordSelect.excluded_columns = nil
125
- instance = controller
126
- warnings = capture_filter_warnings do
127
- assert_equal 3, instance.filters.length
128
- instance.filters
123
+ [nil, [], [:company_id]].each do |allowed|
124
+ assert_raise(ArgumentError) { config(allowed_columns: allowed) }
129
125
  end
130
- assert_equal 2, warnings.length
131
- assert_match(/allowed_columns/, warnings.first)
132
- assert_match(/excluded_columns/, warnings.first)
133
126
  end
134
127
 
135
- def test_unconfigured_filters_do_not_warn_for_reserved_or_unknown_parameters
136
- RecordSelect.excluded_columns = nil
137
- instance = controller
138
- instance.params = {'action' => 'browse', 'unknown' => 'ignored'}
139
- assert_empty capture_filter_warnings { assert_equal [], instance.filters }
128
+ def test_explicit_nil_exclusions_do_not_fall_back_to_the_global_policy
129
+ RecordSelect.excluded_columns = [:password_digest]
130
+ assert_raise(ArgumentError) { config(excluded_columns: nil) }
140
131
  end
141
132
 
142
- def test_explicit_filter_policies_do_not_warn
133
+ def test_controller_can_supply_exclusions_when_global_policy_is_unconfigured
143
134
  RecordSelect.excluded_columns = nil
144
- [{allowed_columns: []}, {allowed_columns: [:company_id]},
145
- {excluded_columns: []}, {excluded_columns: [:password_digest]}].each do |options|
146
- assert_empty capture_filter_warnings { controller(options).filters }
147
- end
148
- end
149
-
150
- def test_global_explicit_compatibility_does_not_warn
151
- RecordSelect.allowed_columns = nil
152
- RecordSelect.excluded_columns = []
153
- assert_empty capture_filter_warnings { assert_equal 3, controller.filters.length }
135
+ assert_equal [{'company_id' => '2'}], controller(allowed_columns: [:company_id], excluded_columns: []).filters
154
136
  end
155
137
 
156
138
  def test_global_settings_are_captured_when_the_controller_is_configured
@@ -180,19 +162,4 @@ class RecordSelectConfigurationTest < ActiveSupport::TestCase
180
162
  assert_equal ['(name LIKE ?)', 'alice%'], instance.text_conditions
181
163
  end
182
164
 
183
- private
184
-
185
- def capture_filter_warnings
186
- deprecator = RecordSelect.deprecator
187
- original_behavior = deprecator.behavior
188
- original_silenced = deprecator.silenced
189
- warnings = []
190
- deprecator.silenced = false
191
- deprecator.behavior = proc { |message, *| warnings << message }
192
- yield
193
- warnings
194
- ensure
195
- deprecator.behavior = original_behavior
196
- deprecator.silenced = original_silenced
197
- end
198
165
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recordselect
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra