0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CakePHP2.x フォームに配列になるようなhiddenを出力するとSecurityComponentでBlackhole送りになる

Posted at

どんなのがダメかというと下記の様に末尾が数字だけの配列になるようなhiddenがダメ。

echo $this->Form->hidden('foo.0', ['value' => 'foo zero']);
echo $this->Form->hidden('foo.1', ['value' => 'foo one']);

このフォームをPOSTすると下記の様なエラーでSecurityComponentでひっかかります。

Tampered field 'foo' in POST data (expected value 'foo one' but found ‘’)

原因はFormHelperの下記の箇所

// ここで末尾の数値なしのフィールド名を取得 foo.0, foo.1 がどちらも foo と判定されちゃう。
$field = preg_replace('/(\.\d+)+$/', '', $field);

if ($lock) {
	if (!in_array($field, $this->fields)) {
		if ($value !== null) {
			// ここでfooの期待値をvalueとして変更不可対象にしてしまう…
			return $this->fields[$field] = $value;

というわけでSecurityComponentを使うならfoo.0みたいに末尾が ".数値" になるフィールド名は避けるのが無難そうです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?