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 +4 -4
- data/README +17 -1
- data/lib/record_select/conditions.rb +0 -1
- data/lib/record_select/config.rb +8 -13
- data/lib/record_select/version.rb +1 -1
- data/lib/record_select.rb +1 -1
- data/test/test_configuration.rb +17 -50
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc39c84fde64efd9594dd1dac16025a735a1cb831d0cf3f66c9bf3e66ee0e3cf
|
|
4
|
+
data.tar.gz: 51a9f5dca54cc08d17adc61a97758c32d4f30ba5a214ec46f8632ff78be6c32f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
|
|
data/lib/record_select/config.rb
CHANGED
|
@@ -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)
|
|
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)) &&
|
|
62
|
+
(allowed.nil? || allowed.include?(name)) && !excluded_columns.include?(name)
|
|
68
63
|
end
|
|
69
64
|
|
|
70
65
|
def order_by
|
data/lib/record_select.rb
CHANGED
data/test/test_configuration.rb
CHANGED
|
@@ -105,52 +105,34 @@ class RecordSelectConfigurationTest < ActiveSupport::TestCase
|
|
|
105
105
|
assert_equal [], controller(allowed_columns: []).filters
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
def
|
|
109
|
-
|
|
108
|
+
def test_default_policy_requires_explicit_exclusions
|
|
109
|
+
assert_equal [], @allowed_columns
|
|
110
110
|
assert_nil @excluded_columns
|
|
111
|
-
RecordSelect.
|
|
112
|
-
|
|
113
|
-
assert_nil config.excluded_columns
|
|
114
|
-
end
|
|
111
|
+
RecordSelect.allowed_columns = @allowed_columns
|
|
112
|
+
RecordSelect.excluded_columns = @excluded_columns
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
assert_equal
|
|
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
|
|
121
|
+
def test_allowlist_does_not_bypass_required_exclusions
|
|
124
122
|
RecordSelect.excluded_columns = nil
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
136
|
-
RecordSelect.excluded_columns =
|
|
137
|
-
|
|
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
|
|
133
|
+
def test_controller_can_supply_exclusions_when_global_policy_is_unconfigured
|
|
143
134
|
RecordSelect.excluded_columns = nil
|
|
144
|
-
[{
|
|
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
|