ransack 4.4.2 → 4.4.3
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/lib/ransack/adapters/active_record/context.rb +4 -0
- data/lib/ransack/constants.rb +9 -0
- data/lib/ransack/context.rb +11 -0
- data/lib/ransack/nodes/grouping.rb +2 -0
- data/lib/ransack/version.rb +1 -1
- 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: 4de514e3bd66dcd465c8253260a52e8fa9e40476a6e1d12b09dae4ed1ec8aaaf
|
|
4
|
+
data.tar.gz: 2f156ce6c2bde6adca76eec24e59cf625e2e53b6922d5a0de370d7a1be75354c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4c4983ce0a10d9afc2f538666f98eeee0eb8f9da168fcd30800ded495cff71807d456e1c462530866d7e5c7954a737fd7127f3badcdb511d48bc9eab22b5d89
|
|
7
|
+
data.tar.gz: 83403fc8e6cfce559597fa844e0ff79b45623dfd285382a2d0d84547263bd8c95f59998c226b7bd5b4c4745e6d70ddf45c6d5e1fd75c9b7278ae4b09592ef150
|
|
@@ -64,6 +64,8 @@ module Ransack
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def attribute_method?(str, klass = @klass)
|
|
67
|
+
return false unless key_within_depth_limit?(str)
|
|
68
|
+
|
|
67
69
|
exists = false
|
|
68
70
|
if ransackable_attribute?(str, klass)
|
|
69
71
|
exists = true
|
|
@@ -237,6 +239,8 @@ module Ransack
|
|
|
237
239
|
end
|
|
238
240
|
|
|
239
241
|
def get_parent_and_attribute_name(str, parent = @base)
|
|
242
|
+
return [parent, nil] unless key_within_depth_limit?(str)
|
|
243
|
+
|
|
240
244
|
attr_name = nil
|
|
241
245
|
|
|
242
246
|
if ransackable_attribute?(str, klassify(parent))
|
data/lib/ransack/constants.rb
CHANGED
|
@@ -50,6 +50,15 @@ module Ransack
|
|
|
50
50
|
|
|
51
51
|
DISTINCT = 'DISTINCT '.freeze
|
|
52
52
|
|
|
53
|
+
# The most `_`-separated segments a single condition or sort key may have
|
|
54
|
+
# before Ransack rejects it as invalid instead of parsing it. Working out
|
|
55
|
+
# whether a key is an attribute, an `_and_`/`_or_` compound or a path
|
|
56
|
+
# through associations is superlinear in this count, and the key comes
|
|
57
|
+
# straight from the query string, so an unbounded one is a CPU-exhaustion
|
|
58
|
+
# denial of service (GHSA-j3f8-w227-4hh8). No real search key is this
|
|
59
|
+
# long: OR-ing every column of a very wide table stays well under it.
|
|
60
|
+
MAX_KEY_DEPTH = 200
|
|
61
|
+
|
|
53
62
|
DERIVED_PREDICATES = [
|
|
54
63
|
[CONT, {
|
|
55
64
|
arel_predicate: 'matches'.freeze,
|
data/lib/ransack/context.rb
CHANGED
|
@@ -47,6 +47,15 @@ module Ransack
|
|
|
47
47
|
@base = @join_dependency.instance_variable_get(:@join_root)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
# False when a key has more `_`-separated segments than Ransack will
|
|
51
|
+
# parse. The attribute / association / predicate parsing that follows is
|
|
52
|
+
# superlinear in the segment count and the key is attacker-controlled, so
|
|
53
|
+
# an over-long key is treated as unknown rather than parsed
|
|
54
|
+
# (GHSA-j3f8-w227-4hh8).
|
|
55
|
+
def key_within_depth_limit?(key)
|
|
56
|
+
key.to_s.count(Constants::UNDERSCORE) <= Constants::MAX_KEY_DEPTH
|
|
57
|
+
end
|
|
58
|
+
|
|
50
59
|
def bind_pair_for(key)
|
|
51
60
|
@bind_pairs ||= {}
|
|
52
61
|
|
|
@@ -124,6 +133,8 @@ module Ransack
|
|
|
124
133
|
end
|
|
125
134
|
|
|
126
135
|
def association_path(str, base = @base)
|
|
136
|
+
return ''.freeze unless key_within_depth_limit?(str)
|
|
137
|
+
|
|
127
138
|
base = klassify(base)
|
|
128
139
|
str ||= ''.freeze
|
|
129
140
|
path = []
|
|
@@ -122,6 +122,8 @@ module Ransack
|
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
def attribute_method?(name)
|
|
125
|
+
return false unless @context.key_within_depth_limit?(name)
|
|
126
|
+
|
|
125
127
|
stripped_name = strip_predicate_and_index(name)
|
|
126
128
|
return true if @context.attribute_method?(stripped_name) ||
|
|
127
129
|
@context.attribute_method?(name)
|
data/lib/ransack/version.rb
CHANGED