Skip to content

Commit

Permalink
Creating correct CSRF tokens when using FormHelper::postLink within a…
Browse files Browse the repository at this point in the history
…nother form. Fixes #8387
  • Loading branch information
MarkusBauer committed Mar 2, 2016
1 parent bafcba3 commit 7df96b3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,13 @@ public function secure($fields = array(), $secureAttributes = array()) {
$tokenFields = array_merge($secureAttributes, array(
'value' => urlencode($fields . ':' . $locked),
'id' => 'TokenFields' . mt_rand(),
'secure' => static::SECURE_SKIP,
));
$out = $this->hidden('_Token.fields', $tokenFields);
$tokenUnlocked = array_merge($secureAttributes, array(
'value' => urlencode($unlocked),
'id' => 'TokenUnlocked' . mt_rand(),
'secure' => static::SECURE_SKIP,
));
$out .= $this->hidden('_Token.unlocked', $tokenUnlocked);
return $this->Html->useTag('hiddenblock', $out);
Expand Down Expand Up @@ -1868,6 +1870,7 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
unset($options['target']);
}

$previousLastAction = $this->_lastAction;
$this->_lastAction($url);

$out = $this->Html->useTag('form', $formUrl, $formOptions);
Expand All @@ -1890,6 +1893,8 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
if ($options['block']) {
$this->_View->append($options['block'], $out);
$out = '';
// Reset security-relevant fields for outer form
$this->_lastAction = $previousLastAction;
}
unset($options['block']);

Expand Down

0 comments on commit 7df96b3

Please sign in to comment.