padrino-admin 0.18.2 → 0.18.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/padrino-admin/access_control.rb +26 -4
- data/test/test_admin_application.rb +232 -0
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4bb555e27244a446b1433ec201e00a5ab6bb895563bb709f8cb6e3b72368cb0a
|
|
4
|
+
data.tar.gz: 299c5bff7ddf533337f11378edba709f94909af649885d126aeba68d59e8ceac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da7e04c9e6b9377d68424fcf0b0f01eb7656b5bac561cb561941756a8a7b3ab6dfafd462e61277e402a404ab3ff06157b7b9d13f0c2648ffbadf28a48c0e3e19
|
|
7
|
+
data.tar.gz: 10b046f9d168867be3e1cdef1b3324cc36eec09779f2d34d9defd00474fd82d1cb8b6f3e41840301711340008997026933c35c903208ee7205a5a9ffaac1eb24
|
|
@@ -36,6 +36,10 @@ module Padrino
|
|
|
36
36
|
# This base access control class where roles are defined as are authorizations.
|
|
37
37
|
#
|
|
38
38
|
class Base
|
|
39
|
+
# How many forms of a request path deny Regexps are checked against at most; a path with more
|
|
40
|
+
# is denied (deny_forms).
|
|
41
|
+
MAX_DENY_FORMS = 64
|
|
42
|
+
|
|
39
43
|
def initialize
|
|
40
44
|
@roles, @authorizations, @project_modules = [], [], []
|
|
41
45
|
end
|
|
@@ -104,8 +108,9 @@ module Padrino
|
|
|
104
108
|
#
|
|
105
109
|
def allowed?(account = nil, path = nil)
|
|
106
110
|
path = '/' if path.nil? || path.empty?
|
|
107
|
-
#
|
|
108
|
-
|
|
111
|
+
# Allow rules see the decoded path the router matches ('%2F' stays inside its segment); deny
|
|
112
|
+
# rules see every form the router may serve it as (deny_forms).
|
|
113
|
+
paths = Padrino::Routing.path_forms(path)
|
|
109
114
|
role = account.role.to_sym rescue nil
|
|
110
115
|
authorizations = @authorizations.find_all { |auth| auth.roles.include?(:any) }
|
|
111
116
|
allowed_paths = authorizations.map(&:allowed).flatten.uniq
|
|
@@ -120,13 +125,30 @@ module Padrino
|
|
|
120
125
|
denied_paths += authorizations.map(&:allowed).flatten.uniq # remove paths explicitly allowed for other roles
|
|
121
126
|
denied_paths += authorizations.map(&:denied).flatten.uniq # remove paths explicitly denied to other roles
|
|
122
127
|
end
|
|
123
|
-
|
|
124
|
-
return
|
|
128
|
+
# A path with a newline satisfies no allow rule.
|
|
129
|
+
return denied_paths.empty? if paths.any? { |form| form.include?("\n") }
|
|
130
|
+
return true if allowed_paths.any? { |p| path_within?(paths.first, p) }
|
|
131
|
+
return true if denied_paths.empty?
|
|
132
|
+
|
|
133
|
+
forms = denied_paths.any?(Regexp) ? deny_forms(paths) : paths
|
|
134
|
+
return false unless forms
|
|
135
|
+
return false if denied_paths.any? { |p| forms.any? { |form| form.start_with?(p) } } # loose on purpose: fails closed
|
|
125
136
|
true
|
|
126
137
|
end
|
|
127
138
|
|
|
128
139
|
private
|
|
129
140
|
|
|
141
|
+
# The forms of the path (Routing.path_forms), without its trailing slashes, and without a
|
|
142
|
+
# format after a dot of its last segment, as a route may serve any of those ('/billing.json'
|
|
143
|
+
# and '/billing/' from '/billing'). Other delimiters start a different page ('/billing-day').
|
|
144
|
+
# A String rule needs none of them: each is a prefix of a decoded form, which start_with?
|
|
145
|
+
# already covers. Returns nil for a path with more than MAX_DENY_FORMS forms, so that it is
|
|
146
|
+
# denied rather than checked in part.
|
|
147
|
+
def deny_forms(paths)
|
|
148
|
+
forms = Padrino::Routing.served_forms(paths).first(MAX_DENY_FORMS + 1)
|
|
149
|
+
forms unless forms.size > MAX_DENY_FORMS
|
|
150
|
+
end
|
|
151
|
+
|
|
130
152
|
# An allowed path covers itself, its sub-paths and its formats ('/posts' allows '/posts',
|
|
131
153
|
# '/posts/1' and '/posts.json'), but not unrelated paths that merely start with it ('/posts_admin').
|
|
132
154
|
# A Regexp matches at the start of the path, as on the deny side.
|
|
@@ -50,6 +50,238 @@ describe 'AdminApplication' do
|
|
|
50
50
|
assert_equal 'unauthenticated', body
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
it 'should require login for a path a protect rule covers, with an encoded letter' do
|
|
54
|
+
mock_app do
|
|
55
|
+
register Padrino::Admin::AccessControl
|
|
56
|
+
enable :sessions
|
|
57
|
+
|
|
58
|
+
access_control.roles_for :any do |role|
|
|
59
|
+
role.protect '/foo'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
get('/foo') { 'foo' }
|
|
63
|
+
get('/bar') { 'bar' }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
['/%66oo', '/f%6Fo', '/%66oo/'].each do |path|
|
|
67
|
+
get path
|
|
68
|
+
assert_equal "You don't have permission for this resource", body, path
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
get '/%62ar'
|
|
72
|
+
assert_equal 'bar', body
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'should keep an encoded slash inside the path segment it is in' do
|
|
76
|
+
mock_app do
|
|
77
|
+
register Padrino::Admin::AccessControl
|
|
78
|
+
enable :sessions
|
|
79
|
+
|
|
80
|
+
access_control.roles_for :any do |role|
|
|
81
|
+
role.protect '/'
|
|
82
|
+
role.allow '/sessions'
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
get('/sessions/:id') { 'session' }
|
|
86
|
+
get('/:page') { "page #{params[:page]}" }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
get '/sessions/new'
|
|
90
|
+
assert_equal 'session', body
|
|
91
|
+
['/sessions%2Fnew', '/sessions%2fnew', '/%73essions%2Fnew'].each do |path|
|
|
92
|
+
get path
|
|
93
|
+
assert_equal "You don't have permission for this resource", body, path
|
|
94
|
+
end
|
|
95
|
+
assert @app.access_control.allowed?(nil, '/sessions/a%2Fb')
|
|
96
|
+
refute @app.access_control.allowed?(nil, '/sessions%2F')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should deny a path a protect rule covers, whose encoded slash a splat route decodes' do
|
|
100
|
+
mock_app do
|
|
101
|
+
register Padrino::Admin::AccessControl
|
|
102
|
+
enable :sessions
|
|
103
|
+
|
|
104
|
+
access_control.roles_for :any do |role|
|
|
105
|
+
role.protect '/files/report'
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
get('/files/:name') { "name #{params[:name]}" }
|
|
109
|
+
get('/*path') { "file #{params[:path]}" }
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
['/files/report', '/files%2Freport', '/files%2freport', '/%66iles%2Freport/1',
|
|
113
|
+
'/files%252Freport', '/files/%2572eport', '/%2566iles/report', '/files/rep%256Frt'].each do |path|
|
|
114
|
+
get path
|
|
115
|
+
assert_equal "You don't have permission for this resource", body, path
|
|
116
|
+
refute @app.access_control.allowed?(nil, path), path
|
|
117
|
+
end
|
|
118
|
+
get '/files/public'
|
|
119
|
+
assert_equal 'name public', body
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe 'with Regexp rules' do
|
|
123
|
+
def denied
|
|
124
|
+
"You don't have permission for this resource"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def mock_filtered_app(&rules)
|
|
128
|
+
mock_app do
|
|
129
|
+
register Padrino::Admin::AccessControl
|
|
130
|
+
enable :sessions
|
|
131
|
+
access_control.roles_for(:any, &rules)
|
|
132
|
+
get('/billing/:a/:b') { 'billing page' }
|
|
133
|
+
get('/admin/:id') { 'admin page' }
|
|
134
|
+
get('/:x/:y') { 'two' }
|
|
135
|
+
get('/:x') { 'one' }
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def assert_not_served(*paths)
|
|
140
|
+
paths.each do |path|
|
|
141
|
+
get path
|
|
142
|
+
assert_includes [401, 404], status, path
|
|
143
|
+
refute_includes ['one', 'two', 'billing page', 'admin page'], body, path
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'should not serve a path that decodes to a newline with an allow Regexp' do
|
|
148
|
+
mock_filtered_app do |role|
|
|
149
|
+
role.protect '/'
|
|
150
|
+
role.allow %r{\A/public$}
|
|
151
|
+
role.allow %r{/lobby$}
|
|
152
|
+
end
|
|
153
|
+
get '/public'
|
|
154
|
+
assert_equal 'one', body
|
|
155
|
+
get '/lobby'
|
|
156
|
+
assert_equal 'one', body
|
|
157
|
+
get '/public/billing'
|
|
158
|
+
assert_equal [401, denied], [status, body]
|
|
159
|
+
assert_not_served '/public%0A/billing', '/lobby%0A/billing'
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'should not serve a path that decodes to a newline with an allow Regexp in a path a protect rule covers' do
|
|
163
|
+
mock_filtered_app do |role|
|
|
164
|
+
role.protect %r{\A/billing/}
|
|
165
|
+
role.allow %r{\A/billing/ok$}
|
|
166
|
+
end
|
|
167
|
+
get '/billing/ok'
|
|
168
|
+
assert_equal 'two', body
|
|
169
|
+
get '/billing/ok/x'
|
|
170
|
+
assert_equal [401, denied], [status, body]
|
|
171
|
+
assert_not_served '/billing/ok%0A/x'
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it 'should not serve a path that decodes to a newline with a protect Regexp' do
|
|
175
|
+
mock_filtered_app do |role|
|
|
176
|
+
role.protect %r{\A/admin/.*\z}
|
|
177
|
+
role.protect %r{^/staff/.+$}
|
|
178
|
+
role.protect %r{\A/billing\z}
|
|
179
|
+
end
|
|
180
|
+
get '/other/x'
|
|
181
|
+
assert_equal 'two', body
|
|
182
|
+
assert_not_served '/admin/1', '/admin/a%0Ab', '/staff/x', '/staff/%0Ab', '/billing', '/billing%0A'
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'should deny the path with a trailing slash for a protect Regexp' do
|
|
186
|
+
mock_filtered_app do |role|
|
|
187
|
+
role.protect %r{\A/billing\z}
|
|
188
|
+
role.protect %r{\A/files/[^/]+\z}
|
|
189
|
+
end
|
|
190
|
+
['/billings', '/billing/x', '/filesx'].each do |path|
|
|
191
|
+
get path
|
|
192
|
+
assert_equal 200, status, path
|
|
193
|
+
end
|
|
194
|
+
['/billing', '/billing/', '/billing//', '/%62illing/', '/files/a/', '/files/a//'].each do |path|
|
|
195
|
+
get path
|
|
196
|
+
assert_equal [401, denied], [status, body], path
|
|
197
|
+
refute @app.access_control.allowed?(nil, path), path
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'should deny the path with a trailing slash for an app mounted under a sub-path' do
|
|
202
|
+
mock_filtered_app do |role|
|
|
203
|
+
role.protect %r{\A/billing\z}
|
|
204
|
+
role.allow %r{\A/public$}
|
|
205
|
+
end
|
|
206
|
+
request = Rack::MockRequest.new(Padrino::Router.new({ path: '/blog', to: @app }, { path: '/', to: @app }))
|
|
207
|
+
assert_equal 'one', request.get('/blog/public').body
|
|
208
|
+
assert_equal 401, request.get('/blog/billing/').status
|
|
209
|
+
['/blog/public%0A/billing', '/blog/billing%0A'].each do |path|
|
|
210
|
+
assert_equal 401, request.get(path).status, path
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should deny the path with a format for a protect Regexp' do
|
|
215
|
+
mock_app do
|
|
216
|
+
register Padrino::Admin::AccessControl
|
|
217
|
+
enable :sessions
|
|
218
|
+
access_control.roles_for :any do |role|
|
|
219
|
+
role.protect %r{\A/billing\z}
|
|
220
|
+
role.protect %r{\A/stock\z}
|
|
221
|
+
end
|
|
222
|
+
get(:billing, map: '/billing', provides: %i[html json]) { 'billing' }
|
|
223
|
+
get('/stock(.:format)?') { 'stock' }
|
|
224
|
+
get('/:x') { 'one' }
|
|
225
|
+
end
|
|
226
|
+
['/billings', '/stocks', '/billing-day', '/billing-json', '/billing_x'].each do |path|
|
|
227
|
+
get path
|
|
228
|
+
assert_equal 'one', body, path
|
|
229
|
+
assert @app.access_control.allowed?(nil, path), path
|
|
230
|
+
end
|
|
231
|
+
['/billing', '/billing/', '/billing.json', '/billing.json/', '/%62illing.json', '/stock', '/stock.json', '/stock.a.b'].each do |path|
|
|
232
|
+
get path
|
|
233
|
+
assert_equal [401, denied], [status, body], path
|
|
234
|
+
refute @app.access_control.allowed?(nil, path), path
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it 'should deny a path with too many forms to check when a protect Regexp exists' do
|
|
239
|
+
mock_app do
|
|
240
|
+
register Padrino::Admin::AccessControl
|
|
241
|
+
enable :sessions
|
|
242
|
+
access_control.roles_for(:any) { |role| role.protect %r{\A/reports/x\z} }
|
|
243
|
+
get('/:name') { 'page' }
|
|
244
|
+
end
|
|
245
|
+
get "/other#{'.a' * 10}"
|
|
246
|
+
assert_equal 'page', body
|
|
247
|
+
get "/other#{'.a' * 70}"
|
|
248
|
+
assert_equal [401, denied], [status, body]
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it 'should answer allowed? for a path with a newline from its deny rules only' do
|
|
252
|
+
mock_app do
|
|
253
|
+
register Padrino::Admin::AccessControl
|
|
254
|
+
access_control.roles_for(:any) do |role|
|
|
255
|
+
role.protect '/admin'
|
|
256
|
+
role.allow %r{\A/public$}
|
|
257
|
+
role.allow '/lobby'
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
["/public\n/admin", '/public%0A/admin', '/lobby%0A', '/lobby/a%250A', '/other%0A'].each do |path|
|
|
261
|
+
refute @app.access_control.allowed?(nil, path), path
|
|
262
|
+
end
|
|
263
|
+
assert @app.access_control.allowed?(nil, '/public')
|
|
264
|
+
mock_app do
|
|
265
|
+
register Padrino::Admin::AccessControl
|
|
266
|
+
access_control.roles_for(:any) { |role| role.allow %r{\A/public$} }
|
|
267
|
+
end
|
|
268
|
+
assert @app.access_control.allowed?(nil, '/public%0A/admin')
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it 'should keep the allow rules of a role for a path with a control character' do
|
|
272
|
+
mock_app do
|
|
273
|
+
register Padrino::Admin::AccessControl
|
|
274
|
+
access_control.roles_for(:any) { |role| role.protect '/' }
|
|
275
|
+
access_control.roles_for(:editor) { |role| role.allow '/posts' }
|
|
276
|
+
access_control.roles_for(:admin) { |role| role.allow '/accounts' }
|
|
277
|
+
end
|
|
278
|
+
editor = Struct.new(:role).new('editor')
|
|
279
|
+
assert @app.access_control.allowed?(editor, '/posts/a%09b')
|
|
280
|
+
assert @app.access_control.allowed?(editor, '/posts/a%0Db')
|
|
281
|
+
refute @app.access_control.allowed?(editor, '/accounts/a%09b')
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
53
285
|
it 'should set basic roles with store location and login page' do
|
|
54
286
|
mock_app do
|
|
55
287
|
set :app_name, :basic_app
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: padrino-admin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.18.
|
|
4
|
+
version: 0.18.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Padrino Team
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2026-11-
|
|
14
|
+
date: 2026-11-03 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: padrino-core
|
|
@@ -19,28 +19,28 @@ dependencies:
|
|
|
19
19
|
requirements:
|
|
20
20
|
- - '='
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.18.
|
|
22
|
+
version: 0.18.3
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - '='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0.18.
|
|
29
|
+
version: 0.18.3
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: padrino-helpers
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
33
33
|
requirements:
|
|
34
34
|
- - '='
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 0.18.
|
|
36
|
+
version: 0.18.3
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
|
41
41
|
- - '='
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: 0.18.
|
|
43
|
+
version: 0.18.3
|
|
44
44
|
description: Admin View for Padrino applications
|
|
45
45
|
email: padrinorb@gmail.com
|
|
46
46
|
executables: []
|