Skip to content

Instantly share code, notes, and snippets.

@anthonycoffey
Last active November 23, 2025 00:00
Show Gist options
  • Select an option

  • Save anthonycoffey/190ac348dd1909abd2e9031840a043c0 to your computer and use it in GitHub Desktop.

Select an option

Save anthonycoffey/190ac348dd1909abd2e9031840a043c0 to your computer and use it in GitHub Desktop.
Description of banned user feature from end to end.

User Banning Process Documentation

This document outlines the end-to-end process for user banning in the application, including the implementation details, impact on users, and potential vulnerabilities.

How User Banning Works

1. Database Schema

The User model in the database contains a boolean field named banned.

  • If banned is false (default), the user is active.
  • If banned is true, the user is considered banned.

2. Banning and Unbanning Logic

The core logic for changing a user's banned status resides in src/services/userService.js.

  • banUser(UserId): Sets the banned flag for the specified user to true.
  • unbanUser(UserId): Sets the banned flag for the specified user to false.

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.

3. Authentication and API Access

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 Forbidden error after attempting to login.
  • Also, for any subsequent request to a protected API endpoint, the middleware checks the banned status.
  • If user.banned is true, the API will return a 403 Forbidden error, preventing the user from accessing any protected resources.

4. UI and Feature Implications

  • Admin Interface: The admin UI in phoenix-ui allows viewing lists of active and banned users separately. The /users page displays users where banned=false, and the /users/banned page displays users where banned=true.
  • Geolocation Services: The geoResults function in src/services/userService.js, which is used for finding nearby technicians, explicitly excludes banned users from its search results.

End-to-End Flow Summary

  1. 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.
  2. Impact on User:
    • The user is not automatically logged out.
    • Login attempts will fail with 403 Forbidden error.
    • Any attempt to access protected API resources will fail with a 403 Forbidden error.
    • The user will be excluded from features like the nearby technician search.

Identified Gaps and Vulnerabilities

  1. 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.
  2. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment