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

Aperta
#331 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
642
Fork
320
Merge medio
3h 9m
PR unite (30g)
11

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NimblePros/eShopOnWeb

Tutte le issue di NimblePros/eShopOnWeb

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.