fix: secure admin rate-limit endpoints with auth in all environments (#369) - #375
Merged
akordavid373 merged 1 commit intoJul 22, 2026
Conversation
…onnect-boiz#369) - Removed NODE_ENV !== production bypass that skipped auth in dev mode - Applied stellarAuth.authenticate middleware to admin rate-limit routes - Implemented role-based access: only users with admin:access permission - Added configurable DEV_ADMIN_TOKEN env var for dev convenience - Extracted admin routes into shared module (backend/src/routes/admin.ts) - Added comprehensive tests: 401 unauthenticated, 403 non-admin, 200 admin
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.
Summary
Fixes #369 - [MEDIUM] Unauthenticated Metrics Endpoint Exposes System Internals in Development Mode
Changes
Problem
Two admin endpoints (
/api/v1/admin/rate-limit/metricsand/api/v1/admin/rate-limit/config) exposed detailed operational metrics. In development mode, the auth check was skipped entirely viaNODE_ENV !== 'production'bypass, allowing attackers to map the API's rate limiting landscape and calibrate attacks.Solution
NODE_ENV !== 'production'bypass — endpoints now require authentication in ALL environmentsstellarAuth.authenticatemiddleware to the admin routesadmin:accesspermission can access these endpoints (403 for non-admin users)DEV_ADMIN_TOKENenv var — configurable development admin token for local convenience (never hardcoded, only in non-production)backend/src/routes/admin.tsfor clean code organization and testabilityFiles Changed
backend/src/index.tsapp.use("/api/v1/admin", adminRoutes)backend/src/routes/admin.tsadminAuthmiddlewarebackend/src/config/env.tsDEV_ADMIN_TOKENto env schemabackend/src/__tests__/admin-rate-limit.test.tsTest Coverage
Acceptance Criteria Checklist
NODE_ENV !== 'production'bypass — auth required in ALL environmentsstellarAuth.authenticateto admin routesDEV_ADMIN_TOKENvia env varcloses [MEDIUM] Unauthenticated Metrics Endpoint Exposes System Internals in Development Mode #369