Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expire user's valid session/tokens after admin deleteing user or changing user's password #333

Open
menghaining opened this issue Dec 12, 2024 · 0 comments

Comments

@menghaining
Copy link

menghaining commented Dec 12, 2024

Description

When the admin deletes the user or changes the user's password, the user's current valid session/token has not expired, leading to the old session/token still being valid.
This would lead to CWE-613 insufficient session expire weakness.


Attack Example

  1. admin login, user1 login;
  2. admin delete user1 or changing user1's password to default;
  3. user1 can still operate with the old session/token which should be expired.

Deleting user by admin

@AdminRequired
@DeleteMapping("/user/{id}")
@PermissionMeta(value = "删除用户", mount = false)
public DeletedVO deleteUser(@PathVariable @Positive(message = "{id.positive}") Integer id) {
adminService.deleteUser(id);
return new DeletedVO(5);
}


Changing password

@AdminRequired
@PutMapping("/user/{id}/password")
@PermissionMeta(value = "修改用户密码", mount = false)
public UpdatedVO changeUserPassword(@PathVariable @Positive(message = "{id.positive}") Integer id, @RequestBody @Validated ResetPasswordDTO validator) {
adminService.changeUserPassword(id, validator);
return new UpdatedVO(4);
}

@PutMapping("/change_password")
@LoginRequired
public UpdatedVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator) {
userService.changeUserPassword(validator);
return new UpdatedVO(4);
}

public boolean changePassword(Integer userId, String password) {
String encrypted = EncryptUtil.encrypt(password);
UserIdentityDO userIdentity = UserIdentityDO.builder().credential(encrypted).build();
QueryWrapper<UserIdentityDO> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(UserIdentityDO::getUserId, userId);
return this.baseMapper.update(userIdentity, wrapper) > 0;
}

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

No branches or pull requests

1 participant