Skip to content

Fix isAdminUserMiddleware ignoring DB errors#399

Open
alex-vydrin wants to merge 1 commit intoOWASP:masterfrom
alex-vydrin:fix/admin-middleware-db-error-handling
Open

Fix isAdminUserMiddleware ignoring DB errors#399
alex-vydrin wants to merge 1 commit intoOWASP:masterfrom
alex-vydrin:fix/admin-middleware-db-error-handling

Conversation

@alex-vydrin
Copy link
Copy Markdown

Summary

  • Bug: isAdminUserMiddleware in app/routes/session.js calls userDAO.getUserById with a callback that receives (err, user) but never checks err. If the database is down or returns an error, the middleware silently treats the request as "not admin" and redirects to /login instead of surfacing the actual error.
  • Fix: Added an if (err) return next(err); check in the callback before evaluating the user, consistent with the error-handling pattern used elsewhere in the same file (e.g., line 267).

Test plan

  • Verify that when the DB returns an error, the middleware calls next(err) and Express's error handler is invoked
  • Verify that normal admin/non-admin flow still works correctly (admin gets through, non-admin is redirected)
  • Run existing test suite (npm test)

Made with Cursor

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.

1 participant