Skip to content

SysRoleController.java:updateRoleStatus未鉴权,可能导致普通用户也能随意调整角色启用/禁用状态 #125

@old6ma

Description

@old6ma

问题描述
SysRoleController.java:updateRoleStatus可以调整角色的启用和禁用状态,但是该函数及其调用的service层函数均未进行鉴权,可能导致普通用户也能随意调整角色启用/禁用状态,具体表现如下:
用户访问updateRoleStatus接口:
@Operation(summary = "修改角色状态") @PutMapping(value = "/{roleId}/status") public Result updateRoleStatus( @Parameter(description ="角色ID") @PathVariable Long roleId, @Parameter(description ="状态(1:启用;0:禁用)") @RequestParam Integer status ) { boolean result = roleService.updateRoleStatus(roleId, status); return Result.judge(result); }
随后调用service层函数updateRoleStatus:
` @OverRide
public boolean updateRoleStatus(Long roleId, Integer status) {
SysRole role = this.getById(roleId);
Assert.isTrue(role != null, "角色不存在");

    role.setStatus(status);
    boolean result = this.updateById(role);
    if (result) {
        // 刷新角色的权限缓存
        roleMenuService.refreshRolePermsCache(role.getCode());
    }

    return result;
}`

整个调用过程中都没有对用户身份进行鉴权,所以可能导致普通用户也可以控制角色状态
建议添加以下鉴权代码:
@PreAuthorize("@ss.hasPerm('sys:role:edit')")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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