Skip to content

Commit ca36a5c

Browse files
committed
fix(auth): correctly propagate exceptions in completeEmailSignIn
Refactors the try-catch block in the `completeEmailSignIn` method to correctly handle exceptions during user lookup and creation. Previously, any `HtHttpException` (including `ForbiddenException` thrown for users without dashboard permissions) was caught and re-thrown as a generic `OperationFailedException`. This masked the original error and prevented the `errorHandler` middleware from returning the correct 403 status code. This change ensures that `HtHttpException` subtypes are re-thrown directly, allowing for proper error handling and correct HTTP responses, thus fixing the authentication vulnerability.
1 parent 1b8616a commit ca36a5c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/src/services/auth_service.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ class AuthService {
256256
'Created default UserContentPreferences for user: ${user.id}',
257257
);
258258
}
259-
} on HtHttpException catch (e) {
260-
_log.severe('Error finding/creating user for $email: $e');
261-
throw const OperationFailedException(
262-
'Failed to find or create user account.',
263-
);
264-
} catch (e) {
259+
} on HtHttpException {
260+
// Propagate known exceptions from dependencies or from this method's logic.
261+
// This ensures that specific errors like ForbiddenException are not
262+
// masked as a generic server error.
263+
rethrow;
264+
} catch (e, s) {
265265
_log.severe(
266-
'Unexpected error during user lookup/creation for $email: $e',
266+
'Unexpected error during user lookup/creation for $email: $e', e, s,
267267
);
268268
throw const OperationFailedException('Failed to process user account.');
269269
}

0 commit comments

Comments
 (0)