mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing issue in Security component with modeless field names, fixes #4454. Thanks vuego for the test and patch!
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6685 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5f8641aac9
commit
ab3b90503f
3 changed files with 40 additions and 12 deletions
|
@ -579,7 +579,11 @@ class SecurityComponent extends Object {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (is_array($value)) {
|
||||||
$keys = array_keys($value);
|
$keys = array_keys($value);
|
||||||
|
} else {
|
||||||
|
$keys = $value;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($field[$key])) {
|
if (isset($field[$key])) {
|
||||||
$field[$key] = array_merge($field[$key], $keys);
|
$field[$key] = array_merge($field[$key], $keys);
|
||||||
|
@ -588,17 +592,19 @@ class SecurityComponent extends Object {
|
||||||
$merge[] = array_keys($fields);
|
$merge[] = array_keys($fields);
|
||||||
}
|
}
|
||||||
$field[$key] = $merge;
|
$field[$key] = $merge;
|
||||||
} else {
|
} else if (is_array($keys)) {
|
||||||
$field[$key] = $keys;
|
$field[$key] = $keys;
|
||||||
|
} else {
|
||||||
|
$field[] = $key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($field as $key => $value) {
|
foreach ($field as $key => $value) {
|
||||||
if(strpos($key, '_') !== 0) {
|
if(strpos($key, '_') !== 0 && is_array($field[$key])) {
|
||||||
sort($field[$key]);
|
sort($field[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ksort($field);
|
ksort($field, SORT_STRING);
|
||||||
|
|
||||||
$check = urlencode(Security::hash(serialize($field) . Configure::read('Security.salt')));
|
$check = urlencode(Security::hash(serialize($field) . Configure::read('Security.salt')));
|
||||||
if ($form !== $check) {
|
if ($form !== $check) {
|
||||||
|
|
|
@ -278,7 +278,7 @@ class FormHelper extends AppHelper {
|
||||||
$append = '<fieldset style="display:none;">';
|
$append = '<fieldset style="display:none;">';
|
||||||
|
|
||||||
foreach ($fields as $key => $value) {
|
foreach ($fields as $key => $value) {
|
||||||
if (strpos($key, '_') !== 0) {
|
if (strpos($key, '_') !== 0 && is_array($fields[$key])) {
|
||||||
sort($fields[$key]);
|
sort($fields[$key]);
|
||||||
} else {
|
} else {
|
||||||
$model = substr($key, 1);
|
$model = substr($key, 1);
|
||||||
|
@ -287,7 +287,7 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ksort($fields);
|
ksort($fields, SORT_STRING);
|
||||||
$append .= $this->hidden('_Token.fields', array('value' => urlencode(Security::hash(serialize($fields) . Configure::read('Security.salt'))), 'id' => 'TokenFields' . mt_rand()));
|
$append .= $this->hidden('_Token.fields', array('value' => urlencode(Security::hash(serialize($fields) . Configure::read('Security.salt'))), 'id' => 'TokenFields' . mt_rand()));
|
||||||
$append .= '</fieldset>';
|
$append .= '</fieldset>';
|
||||||
return $append;
|
return $append;
|
||||||
|
@ -349,6 +349,8 @@ class FormHelper extends AppHelper {
|
||||||
if ((isset($this->fields[$model]) && !in_array($field, $this->fields[$model], true)) || !isset($this->fields[$model])) {
|
if ((isset($this->fields[$model]) && !in_array($field, $this->fields[$model], true)) || !isset($this->fields[$model])) {
|
||||||
if (is_numeric($field)) {
|
if (is_numeric($field)) {
|
||||||
$this->fields[$model][$field][] = $fieldSuffix;
|
$this->fields[$model][$field][] = $fieldSuffix;
|
||||||
|
} else if (is_null($field)) {
|
||||||
|
$this->fields[] = $model;
|
||||||
} else {
|
} else {
|
||||||
$this->fields[$model][] = $field;
|
$this->fields[$model][] = $field;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,26 @@ class SecurityComponentTest extends CakeTestCase {
|
||||||
$this->assertTrue($this->Controller->Session->check('_Token'));
|
$this->assertTrue($this->Controller->Session->check('_Token'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testValidatePostNoModel() {
|
||||||
|
$this->Controller->Security->startup($this->Controller);
|
||||||
|
$key = $this->Controller->params['_Token']['key'];
|
||||||
|
|
||||||
|
$data['anything'] = 'some_data';
|
||||||
|
$data['__Token']['key'] = $key;
|
||||||
|
|
||||||
|
$fields = array('anything',
|
||||||
|
'__Token' => array('key' => $key));
|
||||||
|
|
||||||
|
$fields = $this->__sortFields($fields);
|
||||||
|
|
||||||
|
$fields = urlencode(Security::hash(serialize($fields) . Configure::read('Security.salt')));
|
||||||
|
$data['__Token']['fields'] = $fields;
|
||||||
|
$this->Controller->data = $data;
|
||||||
|
$result = $this->Controller->Security->__validatePost($this->Controller);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertTrue($this->Controller->data == $data);
|
||||||
|
}
|
||||||
|
|
||||||
function testValidatePostSimple() {
|
function testValidatePostSimple() {
|
||||||
$this->Controller->Security->startup($this->Controller);
|
$this->Controller->Security->startup($this->Controller);
|
||||||
$key = $this->Controller->params['_Token']['key'];
|
$key = $this->Controller->params['_Token']['key'];
|
||||||
|
@ -219,11 +239,11 @@ class SecurityComponentTest extends CakeTestCase {
|
||||||
|
|
||||||
function __sortFields($fields) {
|
function __sortFields($fields) {
|
||||||
foreach ($fields as $key => $value) {
|
foreach ($fields as $key => $value) {
|
||||||
if(strpos($key, '_') !== 0) {
|
if(strpos($key, '_') !== 0 && is_array($fields[$key])) {
|
||||||
sort($fields[$key]);
|
sort($fields[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ksort($fields);
|
ksort($fields, SORT_STRING);
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue