Skip to content

fix: secure admin rate-limit endpoints with auth in all environments (#369) - #375

Merged
akordavid373 merged 1 commit into
connect-boiz:mainfrom
davidsoniaudin2-oss:fix/issue-369-unauth-metrics-endpoint
Jul 22, 2026
Merged

fix: secure admin rate-limit endpoints with auth in all environments (#369)#375
akordavid373 merged 1 commit into
connect-boiz:mainfrom
davidsoniaudin2-oss:fix/issue-369-unauth-metrics-endpoint

Conversation

@davidsoniaudin2-oss

@davidsoniaudin2-oss davidsoniaudin2-oss commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #369 - [MEDIUM] Unauthenticated Metrics Endpoint Exposes System Internals in Development Mode

Changes

Problem

Two admin endpoints (/api/v1/admin/rate-limit/metrics and /api/v1/admin/rate-limit/config) exposed detailed operational metrics. In development mode, the auth check was skipped entirely via NODE_ENV !== 'production' bypass, allowing attackers to map the API's rate limiting landscape and calibrate attacks.

Solution

  • Removed the NODE_ENV !== 'production' bypass — endpoints now require authentication in ALL environments
  • Applied stellarAuth.authenticate middleware to the admin routes
  • Implemented role-based access control — only users with admin:access permission can access these endpoints (403 for non-admin users)
  • Added DEV_ADMIN_TOKEN env var — configurable development admin token for local convenience (never hardcoded, only in non-production)
  • Extracted admin routes into backend/src/routes/admin.ts for clean code organization and testability

Files Changed

File Change
backend/src/index.ts Replaced inline admin endpoints with app.use("/api/v1/admin", adminRoutes)
backend/src/routes/admin.ts New — Admin routes with adminAuth middleware
backend/src/config/env.ts Added DEV_ADMIN_TOKEN to env schema
backend/src/__tests__/admin-rate-limit.test.ts New — 14 comprehensive tests

Test Coverage

  • ✅ Unauthenticated → 401 in ALL environments (dev, test, production)
  • ✅ Non-admin user → 403 in ALL environments
  • ✅ Admin user → 200 with full metrics/config
  • ✅ Dev admin token → 200 in non-production
  • ✅ Invalid dev token → 401
  • ✅ Dev token rejection in production → 401

Acceptance Criteria Checklist

…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
@akordavid373
akordavid373 merged commit 270eaec into connect-boiz:main Jul 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] Unauthenticated Metrics Endpoint Exposes System Internals in Development Mode

2 participants