Joomla!バグ修正

2010年 3月 01日(月曜日) 14:56 CrapeMyrtle トラブル解決 - Joomla!
印刷

JCEの修正をしていた際にいくつかバグっぽいものを発見したのでその修正.ユーザが多いみたい(?)なのに結構バグとか残ってるのね….

ちなみに使っているJoomla!のバージョンは1.5.15.

Joomla!の基本モジュール

フロントページから記事の編集を行おうとした場合,textareaにHTMLタグがそのままの形で流し込まれている問題.以下のようなHTMLコードになっている.

<textarea id="text" name="text" cols="70" rows="15" style="width:100%;height:400px;" class="mceEditor">
<p>Hello World!</p>
</textarea>

管理者用の画面から記事編集を行おうとしたら以下のようにちゃんとタグがエスケープされている.

<textarea id="text" name="text" cols="70" rows="15" style="width:100%;height:400px;" class="mceEditor">
&lt;p&gt;Hello World!&lt;/p&gt;
</textarea>

とりあえず場当たり的に/path/to/JoomlaRoot/components/com_content/views/article/tmpl/form.phpの94行目あたりを,以下のように修正.

echo $this->editor->display('text', $this->escape($this->article->text), '100%', '400', '70', '15');

記事の保存の時も,フィルタ(/path/to/JoomlaRoot/libraries/joomla/filter/filterinput.php, JInputFilter::clean)のXSS対策で"&lt;"などが"<"に変換される(何故!?).XSS対策なら逆と思うのだが,こうなっているものは仕方がない.

対策としては,管理者用ページの記事管理 - パラメータ設定で,フィルタグループに適当なものを設定すれば良い.これが設定されていればフィルタグループにマッチしないグループだとこのフィルタを通過することができるが,この設定がなかったら以下のように記事保存時(/path/to/JoomlaRoot/components/com_content/models/article.php, ContentModelArticle::store)内の何かしらのフィルターがかかってしまう.ユーザが複数参加していて,フィルターをちゃんと設定したい場合だとこれどうしてるんだろう….

$gid    = $user->get( 'gid' );
 
$filterGroups    = $config->get( 'filter_groups' );
 
// convert to array if one group selected
if ( (!is_array($filterGroups) && (int) $filterGroups > 0) ) { 
 $filterGroups = array($filterGroups);
}
 
if (is_array($filterGroups) && in_array( $gid, $filterGroups ))
{
 $filterType        = $config->get( 'filter_type' );
 $filterTags        = preg_split( '#[,\s]+#', trim( $config->get( 'filter_tags' ) ) );
 $filterAttrs    = preg_split( '#[,\s]+#', trim( $config->get( 'filter_attritbutes' ) ) );
 switch ($filterType)
 {
 case 'NH':
  $filter    = new JFilterInput();
  break;
 case 'WL':
  $filter    = new JFilterInput( $filterTags, $filterAttrs, 0, 0 );
  break;
 case 'BL':
  default:
  $filter    = new JFilterInput( $filterTags, $filterAttrs, 1, 1 );
  break;
 }
 $article->introtext    = $filter->clean( $article->introtext );
 $article->fulltext    = $filter->clean( $article->fulltext );
} elseif(empty($filterGroups)) {
 $filter = new JFilterInput(array(), array(), 1, 1);
 $article->introtext = $filter->clean( $article->introtext );
 $article->fulltext = $filter->clean( $article->fulltext );
}

GeSHiプラグイン

バグの内容は,コード中の&が&amp;のまま残ってしまうという問題./path/to/JoomlaRoot/plugins/content/geshi.phpの68行目あたりから,以下のように修正.

$text = str_replace('&lt;', '<', $text);
$text = str_replace('&gt;', '>', $text);
$text = str_replace('&amp;', '&', $text); // 追加

たぶんこれだけで大丈夫なはず.

最終更新 2010年 3月 01日(月曜日) 16:07