File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
app-modules/authorization
tests/Tenant/Feature/Http/Controllers Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 4141use Filament \Facades \Filament ;
4242use Illuminate \Http \RedirectResponse ;
4343use Illuminate \Http \Request ;
44+ use Illuminate \Http \Response ;
4445use Illuminate \Support \Facades \Auth ;
4546use Illuminate \Support \Facades \Crypt ;
4647use Illuminate \Support \Facades \Hash ;
@@ -51,8 +52,13 @@ class MagicLinkLoginController
5152 /**
5253 * @throws Throwable
5354 */
54- public function __invoke (Request $ request , LoginMagicLink $ magicLink ): RedirectResponse
55+ public function __invoke (Request $ request , LoginMagicLink $ magicLink ): RedirectResponse | Response
5556 {
57+ if ($ request ->getMethod () === 'HEAD ' ) {
58+ // Protection against link scanning bots, like Microsoft Outlook.
59+ return response ()->noContent ();
60+ }
61+
5662 abort_if (
5763 boolean: now ()->greaterThanOrEqualTo ($ magicLink ->created_at ->addMinutes (15 ))
5864 || $ magicLink ->used_at !== null ,
Original file line number Diff line number Diff line change 4444use function Pest \Laravel \assertAuthenticatedAs ;
4545use function Pest \Laravel \assertGuest ;
4646use function Pest \Laravel \get ;
47+ use function Pest \Laravel \head ;
4748
4849it ('requires a valid signed URL ' , function () {
4950 $ code = Str::random ();
204205
205206 expect ($ magicLink ->used_at )->not ->toBeNull ();
206207});
208+
209+ it ('returns no content for HEAD requests to protect against link scanning bots ' , function () {
210+ $ code = Str::random ();
211+
212+ $ magicLink = LoginMagicLink::factory ()->withCode ($ code )->create ();
213+
214+ $ url = URL ::temporarySignedRoute (
215+ name: 'magic-link.login ' ,
216+ expiration: now ()->addMinutes (10 )->toImmutable (),
217+ parameters: [
218+ 'magicLink ' => $ magicLink ->getKey (),
219+ 'payload ' => urlencode (
220+ Crypt::encrypt (
221+ [
222+ 'code ' => $ code ,
223+ 'user_id ' => $ magicLink ->user_id ,
224+ ]
225+ )
226+ ),
227+ ],
228+ );
229+
230+ head ($ url )
231+ ->assertNoContent ();
232+
233+ $ magicLink ->refresh ();
234+
235+ expect ($ magicLink ->used_at )->toBeNull ();
236+
237+ assertGuest (Filament::getPanel ('admin ' )->getAuthGuard ());
238+ });
You can’t perform that action at this time.
0 commit comments