Skip to content

Commit 710545f

Browse files
committed
Fix handleInvalidData allowing possible return of the next request in the middleware chain
1 parent 0adca00 commit 710545f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Middleware/ValidateWebAppData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function __construct(protected Nutgram $bot)
1313
{
1414
}
1515

16-
public function handle(Request $request, Closure $next)
16+
public function handle(Request $request, Closure $next): mixed
1717
{
1818
try {
1919
$initData = $request->input('initData', '');
@@ -22,11 +22,11 @@ public function handle(Request $request, Closure $next)
2222
$request->attributes->add(['webAppData' => $data]);
2323
return $next($request);
2424
} catch (InvalidDataException) {
25-
$this->handleInvalidData($request, $next);
25+
return $this->handleInvalidData($request, $next);
2626
}
2727
}
2828

29-
protected function handleInvalidData(Request $request, Closure $next): void
29+
protected function handleInvalidData(Request $request, Closure $next): mixed
3030
{
3131
abort(403);
3232
}

tests/Feature/MiddlewareTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@
3232
$middleware->handle($this->request, function ($request) {
3333
});
3434
})->throws(HttpException::class);
35+
36+
it('fails to validate web app data + custom action', function () {
37+
$middleware = new class($this->bot) extends ValidateWebAppData {
38+
protected function handleInvalidData(Request $request, Closure $next): mixed
39+
{
40+
$request->attributes->add(['webAppData' => null]);
41+
return $next($request);
42+
}
43+
};
44+
45+
$middleware->handle($this->request, function ($request) {
46+
expect($request->get('webAppData'))->toBeNull();
47+
});
48+
});

0 commit comments

Comments
 (0)