Skip to content

fix(security): enforce server-side permission checks on identity management endpoints - #1266

Open
NUAAwqy wants to merge 1 commit into
didi:masterfrom
NUAAwqy:fix/server-side-authorization
Open

NUAAwqy wants to merge 1 commit into
didi:masterfrom
NUAAwqy:fix/server-side-authorization

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Nov 16, 2026

Copy link
Copy Markdown

Fixes #1263

Description

The role/permission model (roles, permission points, resource scopes) was only enforced by the web UI to decide which menus and buttons to render. The single interceptor guarding every REST endpoint (PermissionInterceptor) verified the login session but never looked at the caller's roles or permission points, and no controller carried any permission annotation. Consequently any authenticated user — even one deliberately restricted to a single read-only permission point — could call the identity management REST API directly, grant themselves the built-in administrator role or create a hidden administrator account, and take over the platform and every Kafka cluster it manages. The vendor's own Swagger annotation on the user-add endpoint documented the gap directly ("用户新增接口,暂时没有考虑权限").

Changes

  • New IdentityAuthorizationInterceptor (km-rest), registered in WebConfig after PermissionInterceptor so it runs once the login session is validated:
    • maps "HTTP method + URL suffix → required permission point" for the state-changing endpoints of the bundled logi-security controllers: user add/edit/delete (1629/1631/1635), role create/update/delete (1637/1639/1643), role assignment (1641), dept import (1629), config add/edit/delete (1623/1625/1627) and the resource permission-assignment / vpc-switch endpoints (1595, system-management level — self-assignment of resource permissions is another escalation path);
    • resolves the caller's permission points from their roles (UserService.getUserByUserName → UserRoleService.getRoleIdListByUserId → RoleService.getRoleDetailByRoleId().getPermissionTreeVO()) and rejects with HTTP 403 + a JSON error body when the required point is missing;
    • read-only endpoints keep their login-only behaviour so page browsing is unaffected, and endpoints outside /logi-security/api/v1 are unchanged.
  • Permission ids match the rows seeded by km-persistence/src/main/resources/sql/dml-logi.sql, so no schema change is needed and custom roles created through the existing UI keep working.

Test results

  • New IdentityAuthorizationInterceptorTest (9 cases): allow/deny for user and role management writes, role assignment, resource permission assignment, unknown operators, read endpoints and non-identity endpoints. All pass.
  • mvn -pl km-rest -am compile and mvn -pl km-rest -am test -Dtest=IdentityAuthorizationInterceptorTest pass on JDK 11.

Signed-off-by: NUAAwqy 146524024+NUAAwqy@users.noreply.github.com

…gement endpoints

The role/permission model (roles, permission points, resource scopes) was
only enforced by the web UI to decide which menus and buttons to render.
The single interceptor guarding every REST endpoint (PermissionInterceptor)
verified the login session but never looked at the caller's roles or
permission points, and no controller carried any permission annotation.
Consequently any authenticated user - even one restricted to a single
read-only permission point - could call the identity management REST API
directly and grant themselves the built-in administrator role or create a
hidden administrator account, taking over the platform and every Kafka
cluster it manages. The vendor's own Swagger annotation on the user-add
endpoint documented the gap ("用户新增接口,暂时没有考虑权限").

See didi#1263

This adds IdentityAuthorizationInterceptor, registered after the login
interceptor in WebConfig, which enforces the permission model server-side
for state-changing identity/config/resource-assignment endpoints:

- map "HTTP method + URL suffix -> required permission point" for the
  user/role/dept/config endpoints of logi-security and the resource
  permission assignment endpoints, using the permission ids seeded by
  dml-logi.sql (1629 add user, 1637 create role, 1641 assign roles,
  1623/1625/1627 config, 1595 system management for resource assignment)
- resolve the caller's permission points from their roles
  (UserService -> UserRoleService -> RoleService.getPermissionTreeVO)
  and reject with HTTP 403 when the required point is missing
- read-only endpoints keep their login-only behaviour so browsing is
  unaffected; endpoints outside /logi-security/api/v1 are unchanged
- a missing or unknown operator is denied

Unit tests cover allow/deny for user and role management, role
assignment, resource permission assignment, unknown operators, read
endpoints and non-identity endpoints.
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.

Missing server-side authorization allows any authenticated user to escalate to platform administrator

1 participant