Skip to content

Security: Risk recalculation endpoint accessible to all authenticated users — DoS surface #119

@Calebux

Description

@Calebux

Description

POST /api/risk-score/recalculate triggers a full batch recalculation of risk scores for all subscriptions across all users. It is protected only by the standard authenticate middleware (any logged-in user), not the adminAuth middleware.

The route file contains the comment // TODO: Add admin check but it has never been implemented.

Risk

Any authenticated user (including free-tier users) can repeatedly POST to this endpoint, causing the backend to:

  1. Fetch all subscriptions from the database in pages of 100
  2. Run sequential risk calculations on each one
  3. Write updated risk scores back to the database

This is a denial-of-service attack surface that can degrade database performance and backend responsiveness for all users.

Fix

// Add adminAuth middleware to the route
router.post('/recalculate', authenticate, adminAuth, async (req, res) => {
  // ...existing implementation
});

Or alternatively, move the recalculation endpoint to the /api/admin router which already uses adminAuth.

Additional Steps

  • Add rate limiting specific to admin operations
  • Consider making recalculation job-based (triggered by cron) rather than HTTP-triggered
  • Add audit log entry when recalculation is triggered (who triggered it, when)

Metadata

Metadata

Assignees

Labels

BackendStellar WaveIssues in the Stellar wave programbugSomething isn't workingsecuritySecurity vulnerability or concern

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions