From b3d64eea2814cddb237188dae919694e73c364cc Mon Sep 17 00:00:00 2001 From: Stephen Rees-Carter Date: Wed, 13 Jul 2022 18:11:00 +1000 Subject: [PATCH 1/2] Add ignore param to ValidateSignature middleware --- .../Routing/Middleware/ValidateSignature.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/Middleware/ValidateSignature.php b/src/Illuminate/Routing/Middleware/ValidateSignature.php index 59fd368ca058..01163553a329 100644 --- a/src/Illuminate/Routing/Middleware/ValidateSignature.php +++ b/src/Illuminate/Routing/Middleware/ValidateSignature.php @@ -7,6 +7,15 @@ class ValidateSignature { + /** + * The names of the parameters that should be ignored. + * + * @var array + */ + protected $ignore = [ + // + ]; + /** * Handle an incoming request. * @@ -19,7 +28,7 @@ class ValidateSignature */ public function handle($request, Closure $next, $relative = null) { - if ($request->hasValidSignature($relative !== 'relative')) { + if ($request->hasValidSignatureWhileIgnoring($this->ignore, $relative !== 'relative')) { return $next($request); } From d38e7decd977010a90d2061d7f019943cb4e6345 Mon Sep 17 00:00:00 2001 From: Stephen Rees-Carter Date: Wed, 13 Jul 2022 18:56:50 +1000 Subject: [PATCH 2/2] Add test for ValidateSignature $ignore param --- tests/Integration/Routing/UrlSigningTest.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/Integration/Routing/UrlSigningTest.php b/tests/Integration/Routing/UrlSigningTest.php index 532014386d8f..0e56cff63636 100644 --- a/tests/Integration/Routing/UrlSigningTest.php +++ b/tests/Integration/Routing/UrlSigningTest.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Routing\UrlRoutable; use Illuminate\Http\Request; +use Illuminate\Routing\Exceptions\InvalidSignatureException; use Illuminate\Routing\Middleware\ValidateSignature; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Route; @@ -251,6 +252,34 @@ public function testSignedMiddlewareWithRelativePath() $response = $this->get('/foo/relative'); $response->assertStatus(403); } + + public function testSignedMiddlewareIgnoringParameter() + { + Route::get('/foo/{id}}', function (Request $request, $id) { + })->name('foo')->middleware('signed:relative'); + + $this->assertIsString($url = URL::signedRoute('foo', ['id' => 1]).'&ignore=me'); + $request = Request::create($url); + $middleware = $this->createValidateSignatureMiddleware(['ignore']); + + try { + $middleware->handle($request, function ($request) { + $this->assertTrue($request->hasValidSignatureWhileIgnoring(['ignore'])); + }); + } catch (InvalidSignatureException $exception) { + $this->fail($exception->getMessage()); + } + } + + protected function createValidateSignatureMiddleware(array $ignore) + { + return new class ($ignore) extends ValidateSignature { + public function __construct(array $ignore) + { + $this->ignore = $ignore; + } + }; + } } class RoutableInterfaceStub implements UrlRoutable