Skip to content

fix(admin): no password hashes in GET /api/admin/users - #82

Open
alghanim wants to merge 1 commit into
bodaay:masterfrom
alghanim:fix/admin-api-no-password-hashes
Open

alghanim wants to merge 1 commit into
bodaay:masterfrom
alghanim:fix/admin-api-no-password-hashes

Conversation

@alghanim

Copy link
Copy Markdown
Collaborator

Problem

GET /api/admin/users sends every user's bcrypt password hash (password_hash) and password history (password_history, older hashes) in its response. This happens with and without ?include=identities.

  • The Admin UI's Users page calls ?include=identities on every load, so the hashes of all users sit in the admin's browser: in memory, in DevTools, and in any proxy or HAR capture of that traffic.
  • Every other admin response that carries user records already clears both fields: GET /api/admin/users/{guid}, PUT /api/admin/users/{guid} and POST /api/admin/ldap/sync-user. docs/ARCHITECTURE.md documents the rule ("omitted in API responses"). The list call was the one place it was missed.

User is also the storage format (BoltDB JSON, Postgres data JSONB), so the field tags must keep password_hash. The fix is therefore in the responses.

Change

  • withoutPasswords(u) returns a copy of the user without the hash and the history. The stored user is never touched.
  • GET /api/admin/users now uses it in both forms (plain list, and include=identities).
  • The three handlers that cleared the fields in place now use the same helper, so the rule lives in one function. Their behaviour is unchanged.
  • CHANGELOG.md: a Security fixes entry under Unreleased.

Tests

  • internal/handler/password_redaction_test.go, written failing first. A user with a hash and a password history is created, then each of these is called:

    • GET /api/admin/users, plain and ?include=identities;
    • GET /api/admin/users/{guid}, plain and ?include=identities;
    • PUT /api/admin/users/{guid}.

    No response may contain password_hash, password_history, the current hash or the older hash. Before the fix, both list forms failed. Afterwards the stored hash and history are checked unchanged, and a password sign-in still works.

  • go vet ./... and gofmt are clean. go test -race ./...: auth, handler, migrate, store all ok (Go 1.26.8)

Note

🤖 Generated with Claude Code

https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP

The user list (plain and include=identities) returned every user's
bcrypt password_hash and password_history; the Admin UI loads it on
every Users page visit. Every other admin user response already cleared
both (docs/ARCHITECTURE.md: "omitted in API responses"). One helper,
withoutPasswords, now makes the response copy for all four handlers;
the stored user is never touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014xHaYdBuvR8tJcURffAjtP
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