今天無意間又發現 XOOPS 2.7的一個BUG問題,就是儲存頁腳的資訊區塊,原本(XOOPS2.5.11)都還能支援HTML格式,現在貼入內容會被自動清除為純文字格式,這不處理會死人的呢!!頁腳聯絡資訊,網站資訊,還有AA標章,連CSS都沒辦法用,一堆HTML要放的,變成純文字能交差嗎。
經追查資料庫config存進去就已經被過濾成純文字了,研判因該是在儲存端的Xoops安全機制過濾的,於是再反查Xoops的modules/system/admin.php
最後在這裡找到
modules\system\admin\preferences
用筆記本打開找到約第439行
// Detect this and explicitly set an empty array instead.
/* $multiFormTypes = ['select_multi', 'group_multi', 'user_multi', 'theme_multi'];
if (in_array($formType, $multiFormTypes, true) && !Request::hasVar($confName, 'POST')) {
$new_value = [];
} else {
$new_value = Request::getVar($confName, $config->getVar('conf_value'), 'POST');
}*/
替換為
//修改儲存頁腳footer會被自動過成濾純文字的問題$multiFormTypes = ['select_multi', 'group_multi', 'user_multi', 'theme_multi'];
if (in_array($formType, $multiFormTypes, true)
&& !Request::hasVar($confName, 'POST')) {
$new_value = [];
} elseif ($confName === 'footer') {
// Footer historically supports HTML.
$new_value = Request::getText(
$confName,
$config->getVar('conf_value'),
'POST'
);
} else {
$new_value = Request::getVar(
$confName,
$config->getVar('conf_value'),
'POST'
);
}
原因研判
XOOPS 2.5.11 的偏好設定儲存流程,會直接使用已接收的表單變數:
$new_value =& ${$config->getVar('conf_name')};
XOOPS 2.7 將這段改成透過 XMF Request 取得 POST 資料:
$new_value = Request::getVar(
$confName,
$config->getVar('conf_value'),
'POST'
);
Request::getVar() 在沒有指定允許 HTML 或 RAW 模式時,會套用禁止 HTML 的輸入過濾器。這對一般偏好設定欄位有安全價值,但 `footer` 原本就是允許管理員輸入 HTML 的欄位,因此造成既有功能被誤傷。
HTML 是在寫入資料庫之前被移除,所以即使前台佈景使用正確的 Smarty 變數,也無法恢復已經消失的標籤。
儲存修正檔案後,原本只能存文字的頁腳footer欄位就能恢復能存html的功能了,以上工作心得分享,有需要的朋友參考看看!!
工作心得撰寫:徐嘉裕 Neil hsu
留言
張貼留言