From 0fcbd4466f5e2d57260ceedfe505e06960d2a934 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 12 May 2013 21:38:40 -0500 Subject: [PATCH] Include CSRF tokens by default in every non-GET form. #917. --- FormBuilder.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/FormBuilder.php b/FormBuilder.php index 2792817..79c5723 100644 --- a/FormBuilder.php +++ b/FormBuilder.php @@ -705,14 +705,25 @@ class FormBuilder { */ protected function getAppendage($method) { - $method = strtoupper($method); + list($method, $appendage) = array(strtoupper($method), ''); + // If the HTTP method is in this list of spoofed methods, we will attach the + // method spoofer hidden input to the form. This allows us to use regular + // form to initiate PUT and DELETE requests in addition to the typical. if (in_array($method, $this->spoofedMethods)) { - return $this->hidden('_method', $method); + $appendage .= $this->hidden('_method', $method); } - return ''; + // If the method is something other than GET we will go ahead and attach the + // CSRF token to the form, as this can't hurt and is convenient to simply + // always have available on every form the developers creates for them. + if ($method != 'GET') + { + $appendage .= $this->token(); + } + + return $appendage; } /**