[Bug][Medium] username unvalidated and not uniqueness-checked on user update #13

Closed
opened 2026-07-02 01:20:46 +00:00 by wtclaude · 0 comments
Member

Severity: Medium · Type: Bug / validation

Problem

PUT /admin/users/:id validates password and role but not username (server/src/router/v1/admin/admin.routes.js:154-161), yet the controller writes req.body.username (admin.controller.js:485).

  • A blank or too-short username can be saved.
  • A duplicate username is not pre-checked (unlike createUser, which does check) — it hits the DB unique constraint and surfaces as an opaque 500 Internal Server Error.

Suggested fix

Add the same validator used on create and a uniqueness pre-check:

body('username').optional().isString().trim().isLength({ min: 3, max: 32 })

In updateUser, if username is changing, verify no other user already has it and return 409 instead of letting the DB throw.

**Severity:** Medium · **Type:** Bug / validation ## Problem `PUT /admin/users/:id` validates `password` and `role` but **not `username`** (`server/src/router/v1/admin/admin.routes.js:154-161`), yet the controller writes `req.body.username` (`admin.controller.js:485`). - A blank or too-short username can be saved. - A duplicate username is not pre-checked (unlike `createUser`, which does check) — it hits the DB unique constraint and surfaces as an opaque `500 Internal Server Error`. ## Suggested fix Add the same validator used on create and a uniqueness pre-check: ```js body('username').optional().isString().trim().isLength({ min: 3, max: 32 }) ``` In `updateUser`, if `username` is changing, verify no other user already has it and return `409` instead of letting the DB throw.
Sign in to join this conversation.
No description provided.