From 2d3d20152a1ea74c40a7e61700adde0b9c41a531 Mon Sep 17 00:00:00 2001 From: Sebastian Marcet Date: Wed, 9 Jan 2019 12:27:19 -0300 Subject: [PATCH] Fixed issue with LV 5.6 upgrade get current route uri was broken for global middlewares, thus CORS middleware got broken Change-Id: Iaf7a244e67afd8b0f007364f18e5de1ba5af64f1 --- Libs/Utils/RequestUtils.php | 51 ++++++++++--------- app/Http/Middleware/CORSMiddleware.php | 2 +- ...Auth2BearerAccessTokenRequestValidator.php | 2 +- app/Http/Middleware/RateLimitMiddleware.php | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Libs/Utils/RequestUtils.php b/Libs/Utils/RequestUtils.php index ccb735a6..247ad43a 100644 --- a/Libs/Utils/RequestUtils.php +++ b/Libs/Utils/RequestUtils.php @@ -1,20 +1,18 @@ uri(); + public static function getCurrentRoutePath($request) + { + try + { + $route = Route::getRoutes()->match($request); + if(is_null($route)) return false; + $route_path = $route->uri(); if (strpos($route_path, '/') != 0) $route_path = '/' . $route_path; return $route_path; - } - catch (\Exception $ex) - { - Log::error($ex); - } - return false; - } + } + catch (\Exception $ex) + { + Log::error($ex); + } + return false; + } } \ No newline at end of file diff --git a/app/Http/Middleware/CORSMiddleware.php b/app/Http/Middleware/CORSMiddleware.php index 5582dc85..3e36dd5a 100644 --- a/app/Http/Middleware/CORSMiddleware.php +++ b/app/Http/Middleware/CORSMiddleware.php @@ -157,7 +157,7 @@ class CORSMiddleware $real_method = $request->headers->get('Access-Control-Request-Method'); $request->setMethod($real_method); - $route_path = RequestUtils::getCurrentRoutePath(); + $route_path = RequestUtils::getCurrentRoutePath($request); if (!$route_path || !$this->checkEndPoint($route_path, $real_method)) { $response = new Response(); diff --git a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php index 29539d03..26615fdd 100644 --- a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php +++ b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php @@ -86,7 +86,7 @@ class OAuth2BearerAccessTokenRequestValidator try { - $route = RequestUtils::getCurrentRoutePath(); + $route = RequestUtils::getCurrentRoutePath($request); if (!$route) { throw new OAuth2ResourceServerException( 400, diff --git a/app/Http/Middleware/RateLimitMiddleware.php b/app/Http/Middleware/RateLimitMiddleware.php index 31e98b2c..92cebcab 100644 --- a/app/Http/Middleware/RateLimitMiddleware.php +++ b/app/Http/Middleware/RateLimitMiddleware.php @@ -62,7 +62,7 @@ final class RateLimitMiddleware extends ThrottleRequests */ public function handle($request, Closure $next, $max_attempts = 0, $decay_minutes = 0) { - $route = RequestUtils::getCurrentRoutePath(); + $route = RequestUtils::getCurrentRoutePath($request); $method = $request->getMethod(); $endpoint = $this->endpoint_repository->getApiEndpointByUrlAndMethod($route, $method); $key = $this->resolveRequestSignature($request);