Skip to content

Commit

Permalink
Fixed problems with the inability to locally disable antiForgeryToken.
Browse files Browse the repository at this point in the history
Added support for arrays in the function actionNameEquals() and controllerNameEquals().
  • Loading branch information
meet-aleksey committed May 29, 2018
1 parent 3ed8e1c commit 175f2b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
34 changes: 30 additions & 4 deletions src/ActionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,25 @@ public function getActionName() {
/**
* Checks the equivalence of the specified string with the name of the action.
*
* @param string $name The string to compare.
* @param string|array $name The string or string array to compare.
*
* @return bool
*/
public function actionNameEquals($name) {
return strtolower($this->actionName) == strtolower($name);
$actionName = strtolower($this->actionName);

if (is_array($name)) {
foreach ($name as $n) {
if ($actionName == strtolower($n)) {
return true;
}
}

return false;
}
else {
return $actionName == strtolower($name);
}
}

/**
Expand All @@ -196,12 +209,25 @@ public function getControllerName() {
/**
* Checks the equivalence of the specified string with the name of the controller.
*
* @param string $name The string to compare.
* @param string|array $name The string or string array to compare.
*
* @return bool
*/
public function controllerNameEquals($name) {
return strtolower($this->getControllerName()) == strtolower($name);
$controllerName = strtolower($this->getControllerName());

if (is_array($name)) {
foreach ($name as $n) {
if ($controllerName == strtolower($n)) {
return true;
}
}

return false;
}
else {
return $controllerName == strtolower($name);
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/AppBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,11 @@ private static function validation() {

if (!isset($post)) { $post = array(); }

if ((isset($expected) && (!isset($post['__requestVerificationToken']) || $post['__requestVerificationToken'] != $expected)) || (isset($post['__requestVerificationToken']) && empty($expected))) {
if (
(isset($expected) && $expected !== 'false' && (!isset($post['__requestVerificationToken']) || $post['__requestVerificationToken'] != $expected)) ||
(isset($expected) && $expected === 'false' && !empty($post['__requestVerificationToken'])) ||
(isset($post['__requestVerificationToken']) && empty($expected))
) {
throw new HttpAntiForgeryException();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ public static function beginForm($actionName, $controllerName = null, $routeValu
elseif (is_array($antiforgery)) {
$result .= self::antiForgeryToken(true);
}
else {
self::$viewContext->getHttpContext()->getResponse()->addCookie('__requestVerificationToken', 'false', 0, '/', '', false, true);
}

return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
*/
final class Info {

const VERSION = '1.1.0';
const VERSION = '1.1.1';

}

0 comments on commit 175f2b8

Please sign in to comment.