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); } 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