rhino-rails 4.8.0 → 4.8.1
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/rhino/configuration.rb +14 -0
- data/lib/rhino/query_builder.rb +15 -5
- data/lib/rhino/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: c77838e9b0818c083a66439097840287fdfadcd94fe17f7e403b9a1c00e08322
|
|
4
|
+
data.tar.gz: 698536e45e86aed2abd48ba646c0ebc4e821511838c79db07e6525413ace80c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52ec8339ccd944fcb4b3c071bc4829acaf37c1d401abfce18bec28648eac3005d7ca18c407ad3784bc541dcd16cf3238144c8ebd7bbc58ada65b8537f64e0515
|
|
7
|
+
data.tar.gz: '096db647db3f380fe23621e6fc31496321e857a80ce22911bc2133a7877a7e607a49be3e60cb08f88594030c784b9b3a6d3e8f9415969ed0188bfb11569e3ffc'
|
data/lib/rhino/configuration.rb
CHANGED
|
@@ -9,6 +9,12 @@ module Rhino
|
|
|
9
9
|
# model that does not declare its own +rhino_route_key+. Default nil =
|
|
10
10
|
# primary key (today's behavior, fully backward compatible).
|
|
11
11
|
attr_accessor :route_key
|
|
12
|
+
# How many client-selectable named scopes one request may combine with the
|
|
13
|
+
# bracket form (?scope[a]=&scope[b][x]=1). Each scope is an arbitrary query
|
|
14
|
+
# fragment that may add joins or subqueries, so the number is capped: a
|
|
15
|
+
# request over the cap is refused with 403 "Too many scopes requested".
|
|
16
|
+
# Default 3 — a base scope, a window, and one more predicate.
|
|
17
|
+
attr_reader :max_scopes_per_request
|
|
12
18
|
attr_reader :auth
|
|
13
19
|
|
|
14
20
|
def initialize
|
|
@@ -33,6 +39,14 @@ module Rhino
|
|
|
33
39
|
@client_path = nil
|
|
34
40
|
@mobile_path = nil
|
|
35
41
|
@route_key = nil
|
|
42
|
+
@max_scopes_per_request = 3
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# A non-numeric or non-positive value would lock every scope out of every
|
|
46
|
+
# request, so it falls back to the default instead.
|
|
47
|
+
def max_scopes_per_request=(value)
|
|
48
|
+
value = value.to_i if value.respond_to?(:to_i)
|
|
49
|
+
@max_scopes_per_request = value.is_a?(Integer) && value.positive? ? value : 3
|
|
36
50
|
end
|
|
37
51
|
|
|
38
52
|
# Auth configuration accessor. Merges supplied keys over defaults so a host
|
data/lib/rhino/query_builder.rb
CHANGED
|
@@ -12,10 +12,12 @@ module Rhino
|
|
|
12
12
|
# - Fields: ?fields[posts]=id,title,status
|
|
13
13
|
# - Includes: ?include=user,comments
|
|
14
14
|
class QueryBuilder
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
|
|
15
|
+
# Fallback for how many named scopes one request may combine, used when no
|
|
16
|
+
# Rhino configuration is reachable. Apps set +config.max_scopes_per_request+.
|
|
17
|
+
#
|
|
18
|
+
# Scopes are arbitrary query fragments, so stacking many of them is a good
|
|
19
|
+
# way to build an accidental cross join; three covers every real listing.
|
|
20
|
+
DEFAULT_MAX_SCOPES_PER_REQUEST = 3
|
|
19
21
|
|
|
20
22
|
attr_reader :scope, :model_class, :params
|
|
21
23
|
|
|
@@ -109,7 +111,7 @@ module Rhino
|
|
|
109
111
|
{ raw.to_s => "" }
|
|
110
112
|
end
|
|
111
113
|
|
|
112
|
-
raise Rhino::ScopeNotAllowedError, "Too many scopes requested" if requested.size >
|
|
114
|
+
raise Rhino::ScopeNotAllowedError, "Too many scopes requested" if requested.size > max_scopes_per_request
|
|
113
115
|
|
|
114
116
|
permitted = permitted_scope_names
|
|
115
117
|
|
|
@@ -132,6 +134,14 @@ module Rhino
|
|
|
132
134
|
end
|
|
133
135
|
end
|
|
134
136
|
|
|
137
|
+
# How many named scopes this app allows in one request.
|
|
138
|
+
def max_scopes_per_request
|
|
139
|
+
configured = Rhino.config.try(:max_scopes_per_request)
|
|
140
|
+
configured.is_a?(Integer) && configured.positive? ? configured : DEFAULT_MAX_SCOPES_PER_REQUEST
|
|
141
|
+
rescue StandardError
|
|
142
|
+
DEFAULT_MAX_SCOPES_PER_REQUEST
|
|
143
|
+
end
|
|
144
|
+
|
|
135
145
|
# Run one already-authorized named scope, passing the bound arguments in the
|
|
136
146
|
# order the model declared them.
|
|
137
147
|
def run_named_scope(name, entry, args)
|
data/lib/rhino/version.rb
CHANGED