商品登録の時や編集の時、「詳細-メインコメント」欄に<script>のタグを使おうとすると「#script tag escaped#」に変換されます。これはXSSを防ぐための機能なのですが、商品紹介ページでjQueryなどを使ってみた目にインパクトを与えたり、機能を追加したりしたくなったのでちょっといじってみました。
手を加えるファイルは3つです。
/data/Smarty/templates/xxxx/detail.php
Line.54 辺り
■変更前
<p><!–★詳細メインコメント★–><!–{$arrProduct.main_comment|nl2br}–></p>
■変更後
<p><!–★詳細メインコメント★–><!–{$arrProduct.main_comment|nl2br|smarty:nodefaults}–></p>
/data/Smarty/templates/default/admin/products/confirm.php
Line.255 辺り
■変更前
<textarea name=”main_comment” value=”<!–{$arrForm.main_comment|escape}–>” maxlength=”<!–{$smarty.const.LLTEXT_LEN}–>” style=”<!–{if $arrErr.main_comment != “”}–>background-color: <!–{$smarty.const.ERR_COLOR}–><!–{/if}–>” cols=”60″ rows=”8″ class=”area60″><!–{$arrForm.main_comment|escape}–></textarea><br /><span class=”red”> (上限<!–{$smarty.const.LLTEXT_LEN}–>文字)</span></td>
■変更後
<textarea name=”main_comment” value=”<!–{$arrForm.main_comment|escape}–>” maxlength=”<!–{$smarty.const.LLTEXT_LEN}–>” style=”<!–{if $arrErr.main_comment != “”}–>background-color: <!–{$smarty.const.ERR_COLOR}–><!–{/if}–>” cols=”60″ rows=”8″ class=”area60″><!–{$arrForm.main_comment|escape|smarty:nodefaults}–></textarea><br /><span class=”red”> (上限<!–{$smarty.const.LLTEXT_LEN}–>文字)</span></td>
/data/Smarty/templates/default/admin/products/confirm.php
Line.42 辺り
■変更前
<!–{foreach key=key item=item from=$arrForm}–>
<input type=”hidden” name=”<!–{$key}–>” value=”<!–{$item|escape}–>”>
<!–{/foreach}–>
■変更後
<!–{foreach key=key item=item from=$arrForm|smarty:nodefaults}–>
<!–{if $key == “main_comment”}–>
<input type=”hidden” name=”<!–{$key}–>” value=”<!–{$item|escape|smarty:nodefaults}–>”>
<!–{else}–>
<input type=”hidden” name=”<!–{$key}–>” value=”<!–{$item|escape|script_escape}–>”>
<!–{/if}–>
<!–{/foreach}–>
Line.196 辺り
■変更前
<!–{$arrForm.main_comment|nl2br}–>
■変更後
<!–{$arrForm.main_comment|nl2br|smarty:nodefaults}–>
これで「詳細-メインコメント」欄内でjavascriptが利用できるようになりました。
XSSには注意しましょう。
Line.54 辺り
■変更前
<p><!–★詳細メインコメント★–><!–{$arrProduct.main_comment|nl2br}–></p>
■変更後
<p><!–★詳細メインコメント★–><!–{$arrProduct.main_comment|nl2br|smarty:nodefaults}–></p>
タグ:
EC Cube,
Tips
最近のコメント