Skip to content

Add PII field masking in user search endpoint response to prevent data exposure #879

Description

@RUKAYAT-CODER

Overview

src/users/users.controller.ts exposes a search endpoint that returns User entities. If the serialization layer does not strip sensitive fields, PII such as email addresses, phone numbers, and hashed tokens are returned to any authenticated user performing a search, violating the principle of least privilege.

Specifications

Features:

  • Search results must only return non-sensitive fields: id, displayName, avatarUrl, role.
  • Admin-only search endpoints may return additional fields.

Tasks:

  • Create a UserPublicDto containing only safe fields.
  • Apply @Exclude() to sensitive fields in the response serialization for the search endpoint.
  • Add a dedicated UserAdminDto for admin-scoped search results.
  • Add unit tests verifying email is absent from non-admin search results.

Impacted Files:

  • src/users/users.controller.ts
  • src/users/dto/user-public.dto.ts (new)

Acceptance Criteria

  • Non-admin search results do not include email, refreshToken, or passwordHistory.
  • Admin search results include additional fields per the UserAdminDto.
  • Unit tests verify field absence by role.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingsecurity

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions