admin: allow superuser login only on admin.asxp.io
All checks were successful
Build and Deploy to Production / test (push) Successful in 21s
Build and Deploy to Production / build (push) Successful in 59s
Build and Deploy to Production / deploy (push) Successful in 40s

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:
Sergei Poljanski 2026-11-13 06:55:16 +04:00
commit 19cd0fb675
Signed by: asxpi
GPG key ID: 4F8851660FA4121B

View file

@ -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)