Feature: Admin permissions to access the test page - #172
Open
andrea-chirillano wants to merge 1 commit into
Open
Feature: Admin permissions to access the test page#172andrea-chirillano wants to merge 1 commit into
andrea-chirillano wants to merge 1 commit into
Conversation
andrea-chirillano
force-pushed
the
feature/admin-permissions-for-test-page
branch
from
July 27, 2026 13:54
059ab90 to
090d908
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The debug page
/test(which exposes auth test endpoints and project data) was accessible to any logged-in user. This change restricts it to admin users only, on both frontend and backend, and adds a 403 error page for users without permission.Changes
Backend —
backend/app/api/routes/test.py/meand/osmendpoints now requireAdminUser(previouslyCurrentUser), using the existingrequire_adminmechanism fromhotosm_auth_fastapi, which validates the user's email against theADMIN_EMAILSwhitelist.ADMIN_EMAILS. This is the real source of truth: even if the API is called directly (bypassing the frontend), it stays blocked.Frontend —
frontend/src/routes/index.tsx,frontend/src/pages/ForbiddenPage.tsxAdminRoutecomponent that, in addition to checking login state, queries/api/test/meto confirm the user is an admin before renderingTestPage./:locale/testroute now usesAdminRouteinstead ofProtectedRoute.ForbiddenPage.tsx(403 / Access denied), same visual pattern asNotFoundPage.tsx. Shown when a logged-in non-admin user tries to access/test.No CORS changes: this restriction is role-based authorization, not cross-origin —
CORSMiddleware/allow_originsare untouched.Environment / deploy requirements
ADMIN_EMAILS(comma-separated list of emails) was already consumed byrequire_admin, but until now it didn't gate any portal endpoint — this PR is its first real consumer. Needs to be set up/confirmed in each environment:Local (
hot-dev-env): add tohot-dev-env/.env(notportal/.env— that file isn't used by thehot-dev-envstack):Then recreate the container:
docker compose up -d --force-recreate portal-backend(a plain restart won't apply the new value, since docker-compose's${ADMIN_EMAILS}interpolation is resolved at container creation time).Staging and production (GitHub Actions): confirm the
ADMIN_EMAILSsecret is configured in the repo with the real admin emails for each environment. It's already referenced indeploy-testing.ymlanddeploy-production.yml(secrets.ADMIN_EMAILS), but if the secret was never set with real values, those environments will have no effective admin until it's added.Test plan
curlto/api/test/mewith a non-admin user's cookie → 403. With anADMIN_EMAILS-listed user's cookie → 200./test→ seesForbiddenPage(403). Admin user → seesTestPagenormally. Logged-out user → still redirects to home (unchanged).pnpm test(frontend) andpytest(backend) with no regressions.