Commit c19f19a
authored
fix: MFA-enforced accounts leak enumeration via passwordless login guard order (#154)
* fix: MFA-enforced accounts leak enumeration via passwordless login guard order
Root cause: UserController::postLogin()'s shouldRequire2FA() guard ran before
loginWithOTP() validated the submitted OTP, so a caller without the real code
could distinguish MFA-enforced accounts from the rejection message alone -
an account-enumeration oracle requiring no credentials.
Fix: introduce AuthService::loginWithOTPEnforcing2FA(), which checks
shouldRequire2FA() after the OTP is proven valid and before
finalizeRedemption()/Auth::login() - so a guessed/invalid code is rejected
generically before reaching the account-status branch, and a valid code
against an enforced account is rejected before any login side effect
(redemption, Auth::login, the Login event / queued PostLoginUser job) fires.
loginWithOTP() (used by InteractiveGrantType and TokenService's OAuth2 grants)
is unchanged - only UserController::postLogin()'s interactive web login now
enforces 2FA at this layer.
Avoids a boolean flag parameter (flags-over-objects antipattern) by exposing
two explicitly-named public methods delegating to a shared, flag-free
resolveOTPUser() helper.
Adds a regression test proving an invalid OTP against an MFA-enforced
account gets the same generic rejection as any other invalid code.
* test: assert the passwordless rejection is indistinguishable, not just unworded
testInvalidOtpAgainstEnforcedUserDoesNotLeakMFAStatus only asserted that the
flash message lacked the phrase "two-factor authentication". Enumeration is
about distinguishability, so that assertion still passed if a future
enforced-only branch leaked a differently worded message.
It now drives the same invalid code through the same endpoint for the
MFA-enforced admin and for a non-enforced control user, and asserts the two
rejections are byte-identical. The stale flash is cleared between requests so
the comparison cannot read a value against itself. Verified by mutation:
restoring the pre-fix guard order with reworded text fails the new assertSame
and would have passed the old substring assertion.
Also records why testEnforcedUserCannotBypassMFAViaPasswordlessLogin adds no
separate "no login side effect" assertions. Both candidates were tried and
removed as change detectors that cannot fail: the DB-visible effects (OTP
redemption, sibling revocation) are rolled back by the AuthService transaction
regardless of where the guard sits, and the session-visible one (Auth::login()
and the Login event queuing PostLoginUser) is already caught first by the
existing Auth::check() assertion. Both confirmed by mutation.
Full file green: OK (58 tests, 380 assertions).1 parent e72bc80 commit c19f19a
4 files changed
Lines changed: 147 additions & 32 deletions
File tree
- app
- Http/Controllers
- libs
- Auth
- Utils/Services
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | 616 | | |
627 | 617 | | |
628 | 618 | | |
629 | | - | |
| 619 | + | |
630 | 620 | | |
631 | 621 | | |
632 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
276 | 283 | | |
277 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
278 | 294 | | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
293 | 302 | | |
294 | | - | |
295 | | - | |
296 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
297 | 317 | | |
298 | 318 | | |
299 | 319 | | |
300 | | - | |
301 | 320 | | |
302 | | - | |
| 321 | + | |
303 | 322 | | |
304 | 323 | | |
305 | 324 | | |
306 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
307 | 361 | | |
308 | 362 | | |
309 | 363 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
95 | 107 | | |
96 | 108 | | |
97 | 109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
196 | 205 | | |
197 | 206 | | |
198 | 207 | | |
| |||
213 | 222 | | |
214 | 223 | | |
215 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
216 | 275 | | |
217 | 276 | | |
218 | 277 | | |
| |||
0 commit comments