admin: allow superuser login only on admin.asxp.io
Superuser accounts can do everything, so their login should not be exposed on the public site. With SUPERUSER_HOST set, a superuser's correct password on any other host fails exactly like a wrong one, an existing superuser session there counts as none, a password reset sends nothing, and the env recovery login only works on that host. admin.asxp.io is a second Traefik router to the same container, allowed only from WireGuard and the VPC. The host comes from HTTP_HOST, since Rack's request.host would trust a client-sent X-Forwarded-Host. Invite and reset links for regular users use SITE_URL, so an invite created on admin.asxp.io still opens for someone off WireGuard. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
26fa3cc98a
commit
19cd0fb675
1 changed files with 119 additions and 6 deletions
|
|
@ -124,6 +124,24 @@ class UsersAdminTest < Minitest::Test
|
|||
assert last_response.ok?, "#{url.inspect} -> #{last_response.status} #{last_response.body[0, 200]}"
|
||||
end
|
||||
|
||||
def test_superuser_reset_only_on_superuser_host
|
||||
User.create(username: 'root', email: 'root@example.com', superuser: true, password: 'root-password-1')
|
||||
old = ENV['SUPERUSER_HOST']
|
||||
ENV['SUPERUSER_HOST'] = 'admin.example.org'
|
||||
get '/admin/reset'
|
||||
tok = last_response.body[/name="authenticity_token" value="([^"]+)"/, 1]
|
||||
post '/admin/reset', { authenticity_token: tok, login: 'root' }
|
||||
assert last_response.ok?
|
||||
assert_empty Mail::TestMailer.deliveries
|
||||
get 'http://admin.example.org/admin/reset'
|
||||
tok = last_response.body[/name="authenticity_token" value="([^"]+)"/, 1]
|
||||
post 'http://admin.example.org/admin/reset', { authenticity_token: tok, login: 'root' }
|
||||
assert_equal 1, Mail::TestMailer.deliveries.size
|
||||
assert_match %r{http://admin\.example\.org/admin/reset/}, Mail::TestMailer.deliveries.last.body.to_s
|
||||
ensure
|
||||
ENV['SUPERUSER_HOST'] = old
|
||||
end
|
||||
|
||||
def test_no_escalation_by_user_manager
|
||||
boss = User.create(username: 'manager', password: 'manager-pass-1')
|
||||
UserPermission.create(user_id: boss.id, area: 'users', can_read: true, can_write: true)
|
||||
|
|
|
|||
Loading…
Reference in a new issue