Commit 383f555
authored
* fix(auth): require verified local account for OAuth email link
An unverified local signup squatting a victim's email could be silently
annexed by a later OAuth signin (Google/Apple) because the link-by-email
branch only checked `profil.emailVerifiedByProvider`. The pre-existing
local account's own `emailVerified` flag was ignored, so the OAuth signin
inherited the unverified account, its password, and any state attached.
Tighten the gate so the atomic link fires only when both sides vouch for
the email: OAuth provider verified AND local account `emailVerified: true`.
When the local account exists but is unverified, reject with a clear
`VALIDATION_ERROR` instead of falling through to account creation (which
would later throw on the unique-email index with a less actionable error).
- `UserRepository.linkProviderByEmail` filter now includes
`emailVerified: true`; dropped the redundant `$set` of the same field
since the filter already guarantees it.
- `AuthController.checkOAuthUserProfile` branch 3 follows up a null link
with a `findByEmail` to detect the unverified-squatter case and throw
`AppError('oAuth, cannot link to unverified local account', ...)`.
- Integration tests: updated the "link succeeds" case to mark the local
account verified; added a new squatter-rejection test asserting the
local doc is unchanged (no additionalProvidersData, emailVerified still
false, providerData still null).
Closes #3504
* fix(auth): clarify branch-3 race behaviour in link-gate comment
Self-review follow-up: the prior comment didn't explain what happens if
`findByEmail` finds an already-verified user (the rare race where
verification completed between the atomic findOneAndUpdate and the
follow-up lookup). Document that falling through to branch 4 is the
intended behaviour — branch 4 will fail on the unique-email index, and
an OAuth retry will hit branch 3 and link cleanly.
* test(auth): mark signup-gate branch-3 seed as emailVerified
PR #3503 landed a new test for branch 3 that pre-dates this gate change.
It creates a local user then expects the OAuth signin to link — but with
the new gate the link now requires local emailVerified: true. Seed the
local user as verified (same pattern as the existing link-succeeds test)
so the test continues to exercise the happy path post-rebase.
1 parent 9a1a513 commit 383f555
3 files changed
Lines changed: 92 additions & 9 deletions
File tree
- modules
- auth
- controllers
- tests
- users/repositories
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
365 | 370 | | |
366 | 371 | | |
367 | 372 | | |
368 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
369 | 392 | | |
| 393 | + | |
370 | 394 | | |
371 | 395 | | |
372 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
751 | | - | |
752 | | - | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
753 | 754 | | |
754 | 755 | | |
755 | 756 | | |
| |||
759 | 760 | | |
760 | 761 | | |
761 | 762 | | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
762 | 766 | | |
763 | 767 | | |
764 | 768 | | |
| |||
786 | 790 | | |
787 | 791 | | |
788 | 792 | | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
789 | 839 | | |
790 | 840 | | |
791 | 841 | | |
| |||
995 | 1045 | | |
996 | 1046 | | |
997 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
998 | 1052 | | |
999 | 1053 | | |
1000 | 1054 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
200 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
201 | 206 | | |
202 | 207 | | |
203 | 208 | | |
204 | | - | |
205 | | - | |
| 209 | + | |
| 210 | + | |
206 | 211 | | |
207 | 212 | | |
208 | 213 | | |
| |||
0 commit comments