Skip to content

Commit bbbff11

Browse files
committed
fix(auth): prevent code requests for invalid dashboard users
Refactors the validation logic in `AuthService.initiateEmailSignIn` to correct a critical security flaw. Previously, the logic allowed verification codes to be sent to any email address during a dashboard login attempt, even if the user did not exist or lacked permissions. This change restructures the validation into a more explicit `if-else if` block. It now correctly throws an `UnauthorizedException` if the user is not found or a `ForbiddenException` if they lack permissions, ensuring that execution is halted immediately and a code is never sent for an invalid dashboard login attempt.
1 parent 9a2b1e9 commit bbbff11

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/src/services/auth_service.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,23 @@ class AuthService {
7575
// For dashboard login, first validate the user exists and has permissions.
7676
if (isDashboardLogin) {
7777
final user = await _findUserByEmail(email);
78+
79+
// For dashboard login, the user must exist AND have permission.
80+
// If either condition fails, throw the appropriate exception.
7881
if (user == null) {
7982
_log.warning('Dashboard login failed: User $email not found.');
8083
throw const UnauthorizedException(
8184
'This email address is not registered for dashboard access.',
8285
);
83-
}
84-
85-
// Use the PermissionService to check for the specific dashboard login permission.
86-
if (!_permissionService.hasPermission(
87-
user,
88-
Permissions.dashboardLogin,
89-
)) {
86+
} else if (!_permissionService.hasPermission(user, Permissions.dashboardLogin)) {
9087
_log.warning(
9188
'Dashboard login failed: User ${user.id} lacks required permission (${Permissions.dashboardLogin}).',
9289
);
9390
throw const ForbiddenException(
9491
'Your account does not have the required permissions to sign in.',
9592
);
9693
}
94+
9795
_log.info('Dashboard user ${user.id} verified successfully.');
9896
}
9997

0 commit comments

Comments
 (0)