mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
fix(security): authentication bypass via non-null default userdetail on auth failure
When `getSubject()` returns null (e.g., no Shiro session, expired token, or exception) or when `getPrincipal()` is null, the method returns `new UserDetail()` instead of null. This means callers performing null-check guards (e.g., `if (SecurityUser.getUser() != null)`) will believe an authenticated user exists when none does. Additionally, `getSubject()` silently swallows all exceptions and returns null, masking authentication infrastructure failures. Any downstream code relying on a null return to deny access will be bypassed with a default UserDetail object. Affected files: SecurityUser.java Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>
This commit is contained in:
parent
06b0ff139b
commit
61675f423b
1 changed files with 6 additions and 4 deletions
|
|
@ -26,25 +26,27 @@ public class SecurityUser {
|
|||
public static UserDetail getUser() {
|
||||
Subject subject = getSubject();
|
||||
if (subject == null) {
|
||||
return new UserDetail();
|
||||
return null;
|
||||
}
|
||||
|
||||
UserDetail user = (UserDetail) subject.getPrincipal();
|
||||
if (user == null) {
|
||||
return new UserDetail();
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public static String getToken() {
|
||||
return getUser().getToken();
|
||||
UserDetail user = getUser();
|
||||
return user != null ? user.getToken() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
return getUser().getId();
|
||||
UserDetail user = getUser();
|
||||
return user != null ? user.getId() : null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue