diff --git a/src/Controller/Component/CsrfComponent.php b/src/Controller/Component/CsrfComponent.php index 0a8e611b05d..a5207a2bf1d 100644 --- a/src/Controller/Component/CsrfComponent.php +++ b/src/Controller/Component/CsrfComponent.php @@ -16,7 +16,7 @@ use Cake\Controller\Component; use Cake\Event\Event; -use Cake\Network\Exception\ForbiddenException; +use Cake\Network\Exception\InvalidCsrfTokenException; use Cake\Network\Request; use Cake\Network\Response; use Cake\Utility\Security; @@ -30,7 +30,7 @@ * PUT, or DELETE request. * * If the request data is missing or does not match the cookie data, - * a ForbiddenException will be raised. + * an InvalidCsrfTokenException will be raised. * * This component integrates with the FormHelper automatically and when * used together your forms will have CSRF tokens automatically added @@ -135,7 +135,7 @@ protected function _setCookie(Request $request, Response $response) * Validate the request data against the cookie token. * * @param \Cake\Network\Request $request The request to validate against. - * @throws \Cake\Network\Exception\ForbiddenException when the CSRF token is invalid or missing. + * @throws \Cake\Network\Exception\InvalidCsrfTokenException when the CSRF token is invalid or missing. * @return void */ protected function _validateToken(Request $request) @@ -145,11 +145,11 @@ protected function _validateToken(Request $request) $header = $request->header('X-CSRF-Token'); if (empty($cookie)) { - throw new ForbiddenException(__d('cake', 'Invalid CSRF token.')); + throw new InvalidCsrfTokenException(__d('cake', 'Missing CSRF token cookie')); } if ($post !== $cookie && $header !== $cookie) { - throw new ForbiddenException(__d('cake', 'Invalid CSRF token.')); + throw new InvalidCsrfTokenException(__d('cake', 'CSRF token mismatch.')); } } } diff --git a/src/Network/Exception/InvalidCsrfTokenException.php b/src/Network/Exception/InvalidCsrfTokenException.php new file mode 100644 index 00000000000..f372cafc166 --- /dev/null +++ b/src/Network/Exception/InvalidCsrfTokenException.php @@ -0,0 +1,35 @@ +