Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ class="col-head bca-form-table__label"><?php echo $this->BcAdminForm->label('opt
<td class="col-input bca-form-table__input">
<?php echo $this->BcAdminForm->control('options', ['type' => 'text', 'size' => 40, 'maxlength' => 255]) ?>
<?php echo $this->BcAdminForm->error('options') ?>
<i class="bca-icon--question-circle bca-help"></i>
<div class="bca-helptext">
<p>inputタグに対してオプションを設定します。</p>
<dl>
<dt>placeholder</dt>
<dd>プレースホルダー:利用するには、次の形式のように | 区切りで入力します。「placeholder|プレースホルダーの内容」</dd>
<dt>empty</dt>
<dd>セレクトボックスの何も選択していないときの表示は、次の形式のように | 区切りで入力します。「empty|何も選択していないときのメッセージ」</dd>
<dt>templateVars.tag</dt>
<dd>マルチチェックボックスでそれぞれのインプットタグをラッピングする要素を指定します。例)templateVars.tag|div class="checkbox"(div class="checkbox"で囲む)<br>※デフォルトはspanタグでラッピングされます。</dd>
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ヘルプテキストの例に誤解を招く可能性があります。「div class="checkbox"」という例は、クラス属性を含むタグを指定できることを示唆していますが、実際のコード実装ではこれが適切に処理されていません(セキュリティとロジックの問題については他のコメントを参照)。

実装が修正されるまで、ヘルプテキストの例を単純なタグ名のみに変更することを推奨します。例:「templateVars.tag|div」

Suggested change
<dd>マルチチェックボックスでそれぞれのインプットタグをラッピングする要素を指定します。例)templateVars.tag|div class="checkbox"(div class="checkbox"で囲む)<br>※デフォルトはspanタグでラッピングされます。</dd>
<dd>マルチチェックボックスでそれぞれのインプットタグをラッピングする要素を指定します。例)templateVars.tag|div(divタグで囲む)<br>※デフォルトはspanタグでラッピングされます。</dd>

Copilot uses AI. Check for mistakes.
</dl>
</div>
</td>
</tr>
<tr id="RowAutoComplete">
Expand Down
29 changes: 29 additions & 0 deletions plugins/bc-mail/src/View/Helper/MailformHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,35 @@ public function control(string $fieldName, array $attributes = []): string
$attributes['value'] = null;
$attributes['empty'] = false;
$attributes['templateVars']['tag'] = 'span';
// オプションでtemplateVars.tagが指定されていた場合の対応
if (!empty($attributes['templateVars.tag'])) {
// 取得した値が有効なタグか確認
$validTags = ['div', 'span', 'p', 'li', 'dt', 'dd', 'label'];
$rawTemplateTag = $attributes['templateVars.tag'];
foreach ($validTags as $validTag) {
// templateVars.tagが有効なタグ名から始まっている場合、$attributes['templateVars']['tag'] にセット
if (str_starts_with($rawTemplateTag, $validTag)) {
// 検証済みのタグ名のみをtemplateVars['tag']にセット
$attributes['templateVars']['tag'] = $validTag;
// 先頭のタグ名以降の文字列を取得(例: ' class="checkbox"')
$rest = trim(substr($rawTemplateTag, strlen($validTag)));
if ($rest !== '') {
$rests = explode(' ', $rest);
foreach ($rests as $key => $restPart) {
// タグ名を除外した属性値の中で、onclickやonchangeなどのイベント属性が含まれている場合、unsetする
if (str_starts_with($restPart, 'on')) {
unset($rests[$key]);
}
}
if (!empty($rests) && isset($attributes['templateVars']['tag'])) {
$attributes['templateVars']['tag'] .= ' ' . implode(' ', $rests);
}
}
}
}
Comment on lines +183 to +203
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有効なタグに一致しない場合の処理が不完全です。ループ内でbreakが実行されなかった場合(つまり、有効なタグが見つからなかった場合)、$attributes['templateVars']['tag'] はデフォルトの 'span' のままになりますが、無効な入力に対する明示的な処理やログ記録がありません。

無効な値が入力された場合は、警告ログを記録するか、デフォルト値を使用していることをユーザーに通知することを検討してください。

Copilot uses AI. Check for mistakes.
// inputタグに出力されないようにunset
unset($attributes['templateVars.tag']);
}
Comment on lines +179 to +206
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セキュリティ上の懸念:$attributes['templateVars.tag'] の値がそのままHTMLに出力される可能性があります。ユーザーが div onclick="alert('XSS')" のような悪意のある入力を行った場合、XSS脆弱性につながる可能性があります。

タグ名と属性を分離し、属性値を適切にエスケープする処理を追加することを推奨します。または、属性の指定を許可せず、タグ名のみを受け入れるように仕様を変更することも検討してください。

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +206
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しく追加された templateVars.tag オプション処理機能に対するユニットテストが不足しています。以下のテストケースを追加することを推奨します:

  1. 有効なタグ名(例:'div', 'span', 'p')が正しく処理されることを確認
  2. タグ名とクラス属性を含む入力(例:'div class="checkbox"')の処理を確認
  3. 無効なタグ名が入力された場合のデフォルト動作を確認
  4. templateVars.tag が指定されていない場合のデフォルト動作を確認

MailformHelperTest.php に testControlWithTemplateVarsTag のようなテストメソッドを追加してください。

Copilot uses AI. Check for mistakes.
$out = $this->select($fieldName, $options, $attributes);
break;
case 'file':
Expand Down
Loading