From 174325179d9596e6129156997b8336144744a24e Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 24 Aug 2020 15:16:27 +0200 Subject: [PATCH] [12.x] Fail url checking when url is invalid (#984) * Fail url checking when url is invalid * Update VerifyRedirectUrl.php Co-authored-by: Taylor Otwell --- src/Http/Middleware/VerifyRedirectUrl.php | 4 +++- tests/Unit/VerifyRedirectUrlTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Http/Middleware/VerifyRedirectUrl.php b/src/Http/Middleware/VerifyRedirectUrl.php index 3dd6cc9f..23cf6312 100644 --- a/src/Http/Middleware/VerifyRedirectUrl.php +++ b/src/Http/Middleware/VerifyRedirectUrl.php @@ -20,7 +20,9 @@ public function handle($request, Closure $next) { $redirect = $request->get('redirect'); - if ($redirect && parse_url($redirect)['host'] !== $request->getHost()) { + $url = parse_url($redirect); + + if ($redirect && (! isset($url['host']) || $url['host'] !== $request->getHost())) { throw new AccessDeniedHttpException('Redirect host mismatch.'); } diff --git a/tests/Unit/VerifyRedirectUrlTest.php b/tests/Unit/VerifyRedirectUrlTest.php index 77524ae7..a7a953f7 100644 --- a/tests/Unit/VerifyRedirectUrlTest.php +++ b/tests/Unit/VerifyRedirectUrlTest.php @@ -33,6 +33,18 @@ public function test_it_fails_on_host_mismatch() }); } + public function test_it_fails_when_the_url_is_invalid() + { + $request = Request::create('http://baz.com/stripe/payment', 'GET', ['redirect' => 'foo/bar']); + $middleware = new VerifyRedirectUrl; + + $this->expectException(AccessDeniedHttpException::class); + + $middleware->handle($request, function () { + // + }); + } + public function test_it_is_skipped_when_no_redirect_is_present() { $request = Request::create('http://baz.com/stripe/payment', 'GET');