This bounty involves adding a role-based authorization check to an existing admin metrics endpoint in a Node.js API. The current setup only validates the JWT, allowing any authenticated user to access admin-only data. The task is to ensure only users with the 'admin' role can access the `/api/admin/metrics` route.
A starter prompt for Claude Code, what you'll need, and how to reach them.
You are an expert Node.js developer. The goal is to implement a role-based authorization check for an existing admin metrics endpoint in a `SecureBananaLabs/bug-bounty` repository. The target endpoint is `/api/admin/metrics` within `apps/api/src/routes/adminRoutes.js`. The current `authMiddleware` only verifies JWT validity, but any authenticated user (including 'client' or 'freelancer' roles) can access it. Implement a new middleware, `adminRoleMiddleware`, that verifies `req.user.role === 'admin'`. If the role is not 'admin', respond with a 403 Forbidden status and an appropriate error message. Integrate this `adminRoleMiddleware` specifically into the `/api/admin/metrics` route within `adminRoutes.js`. Assume `req.user.role` is reliably populated by the preceding `authMiddleware`. Provide the code changes for `adminRoutes.js` and any new middleware files, and include a simple test plan to verify the fix. Use Node.js, Express.js. Focus on minimal, effective changes.
Standard for any GitHub-based project.
Bounty (amount on the issue). ## Description The admin routes in `apps/api/src/routes/adminRoutes.js` currently only use `authMiddleware` which verifies that the JWT is valid, but they do not perform any role-based authorization check to ensure the user has the `admin` role. This allows any authenticated client or freelancer to access the admin metrics endpoint at `/api/admin/metrics`. ## Expected Behavior Access to `/api/admin/metrics` should be restricted to users with the `admin` role. An authorization check or middleware should be added to verify `req.user.role === 'admin'`. --- This issue is limited only to the creator of this issue. This means that only the issue author can attempt to solve this issue. If you would like to work on it, please create another issue with the same contents and refer to issue #743 for more information.
Standard for Node.js projects.
Core skill for Node.js API development.
Create a new GitHub issue on the SecureBananaLabs/bug-bounty repository with the same contents as issue #1764, explicitly referring to issue #743 for the process, then work on your new issue's branch.
“I've identified the security flaw and am ready to implement the fix for the missing admin role authorization on the `/api/admin/metrics` endpoint. I've created a new issue and will submit a PR with the robust solution to secure your admin routes.”
Open the original ↗