This document outlines the end-to-end process for user banning in the application, including the implementation details, impact on users, and potential vulnerabilities.
The User model in the database contains a boolean field named banned.
- If
bannedisfalse(default), the user is active. - If
bannedistrue, the user is considered banned.
The core logic for changing a user's banned status resides in src/services/userService.js.
banUser(UserId): Sets thebannedflag for the specified user totrue.unbanUser(UserId): Sets thebannedflag for the specified user tofalse.
Additionally, when a user's account is deleted via the deleteAccount function in src/controllers/accountController.js, the banned flag is set to true as part of the anonymization and deletion process.
The requiresAuth middleware in src/middleware/auth.js is crucial for enforcing the ban.
- A banned user cannot login and receive a valid authentication token. They receive
403 Forbiddenerror after attempting to login. - Also, for any subsequent request to a protected API endpoint, the middleware checks the
bannedstatus. - If
user.bannedistrue, the API will return a403 Forbiddenerror, preventing the user from accessing any protected resources.
- Admin Interface: The admin UI in
phoenix-uiallows viewing lists of active and banned users separately. The/userspage displays users wherebanned=false, and the/users/bannedpage displays users wherebanned=true. - Geolocation Services: The
geoResultsfunction insrc/services/userService.js, which is used for finding nearby technicians, explicitly excludes banned users from its search results.
- Initiating a Ban: A ban is initiated by either an administrator directly calling the
userService.banUser()function from the frontend or by a user's account being deleted via anonymization feature. - Impact on User:
- The user is not automatically logged out.
- Login attempts will fail with
403 Forbiddenerror. - Any attempt to access protected API resources will fail with a
403 Forbiddenerror. - The user will be excluded from features like the nearby technician search.
- No Audit Trail: The system does not record who banned or unbanned a user, or the reason for the action. This makes accountability and tracking difficult.
- No User Notification: The user is not informed when their account status changes. They only discover the ban when they are denied access to resources.