Skip to content

Commit ad65ef2

Browse files
committed
fix(auth): improve dashboard login security
- Added email verification for dashboard login - Improved error handling for email mismatch - Enhanced logging for security issues - Added more informative error messages - Fixed potential security vulnerability
1 parent bbbff11 commit ad65ef2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/src/services/auth_service.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,25 @@ class AuthService {
166166
// This closes the loophole where a non-admin user could request a code
167167
// via the app flow and then use it to log into the dashboard.
168168
if (isDashboardLogin) {
169+
if (user.email != email) {
170+
// This is a critical security check. If the user found by email
171+
// somehow has a different email than the one provided, it's a
172+
// sign of a serious issue (like the data layer bug we fixed).
173+
// We throw a generic error to avoid revealing information.
174+
_log.severe(
175+
'CRITICAL: Mismatch between requested email ($email) and found '
176+
'user email (${user.email}) during dashboard login for user '
177+
'ID ${user.id}.',
178+
);
179+
throw const UnauthorizedException('User account does not exist.');
180+
}
169181
if (!_permissionService.hasPermission(
170182
user,
171183
Permissions.dashboardLogin,
172184
)) {
173185
_log.warning(
174-
'Dashboard login failed: User ${user.id} lacks required permission '
175-
'during code verification.',
186+
'Dashboard login failed: User ${user.id} lacks required '
187+
'permission during code verification.',
176188
);
177189
throw const ForbiddenException(
178190
'Your account does not have the required permissions to sign in.',

0 commit comments

Comments
 (0)