Skip to content

Commit 4938e95

Browse files
authored
Prevent head requests triggering run on null, thanks to @jamesdb (#123)
1 parent b93bbdf commit 4938e95

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Middlewares/MagiclinkMiddleware.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class MagiclinkMiddleware
1111
{
1212
public function handle(Request $request, Closure $next)
1313
{
14-
if ($request->method() === 'HEAD') {
15-
return $next($request);
16-
}
17-
1814
$token = (string) $request->route('token');
1915

2016
$magicLink = MagicLink::getValidMagicLinkByToken($token);
2117

18+
if ($request->method() === 'HEAD') {
19+
return response()->noContent($magicLink ? 200 : 404);
20+
}
21+
2222
if (! $magicLink) {
2323
return $this->badResponse();
2424
}

tests/HttpTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,14 @@ public function test_http_urlencode_legacy()
7373
->assertStatus(200)
7474
->assertSeeText('private content');
7575
}
76+
77+
public function test_http_head_request_without_valid_magiclink()
78+
{
79+
$magiclink = MagicLink::create(new ResponseAction(function () {
80+
return 'private content';
81+
}));
82+
83+
$this->head($magiclink->url . '-bad')
84+
->assertStatus(404);
85+
}
7686
}

0 commit comments

Comments
 (0)