[Security] Role endpoints return the raw IdentityRole entity instead of a DTO

Open
#331 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
api, backend

Research direction

Start with src/PublicApi/RoleManagementEndpoints/CreateRoleEndpoint.CreateRoleResponse.cs and the three sibling response files to see how each endpoint currently returns IdentityRole, then copy the UserDto pattern used for the #324 fix. On the client side follow Services/RoleManagementService.cs and the four Models/*RoleResponse.cs types into Pages/RolePage/* and the two Pages/UserPage files to see where the entity's extra fields are bound. Finish by mirroring tests/PublicApiIntegrationTests/Helpers/UserJsonAssert.cs so role responses assert only id and name, and run the PublicApi integration tests plus a BlazorAdmin build.

Written by the indexing model from the issue text.

Description

bug

Summary

The role management endpoints serialize the ASP.NET Identity entity IdentityRole directly in their responses:

  • src/PublicApi/RoleManagementEndpoints/CreateRoleEndpoint.CreateRoleResponse.cs:14
  • src/PublicApi/RoleManagementEndpoints/RoleGetByIdEndpoint.GetByIdRoleResponse.cs:17
  • src/PublicApi/RoleManagementEndpoints/RoleListEndpoint.RoleListResponse.cs:17
  • src/PublicApi/RoleManagementEndpoints/UpdateRoleEndpoint.UpdateRoleResponse.cs:15

This exposes NormalizedName and ConcurrencyStamp. Neither is secret, but it couples the public API contract to the Identity storage model. That is the same pattern that led to the PasswordHash leak in #324, where the user endpoints were fixed to return UserDto.

Impact (Low)

Internal persistence fields are visible to clients. Any future change to the role entity (custom role class, extra columns) would be published automatically.

Suggested fix

  • Add a RoleDto { Id, Name } and return it from all four endpoints.
  • Update BlazorAdmin, which binds IdentityRole throughout: Models/CreateRoleResponse.cs, Models/GetByIdRoleResponse.cs, Models/RoleListResponse.cs, Services/RoleManagementService.cs, Pages/RolePage/*, Pages/UserPage/Create.razor, Pages/UserPage/Edit.razor.
  • Reuse the allowlist approach from tests/PublicApiIntegrationTests/Helpers/UserJsonAssert.cs (added in #329) to assert role responses only contain id and name.

Found during the independent review of #329.

Dominant language
C#
Stars
642
Forks
320
Avg merge
3h 9m
Merged PRs (30d)
11

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NimblePros/eShopOnWeb

All issues in NimblePros/eShopOnWeb

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.