10

私はHTMLPurifierHTML文字列をサニタイズするために使用しています(これはセキュリティに関するものです)。

HTMLPurifierが呼び出されると、一部の属性(widthまたはなどheight)が削除されます。私はこれをセキュリティの問題とは考えていません。

ホワイトリストを再定義せずにこの属性を追加するにはどうすればよいですか?

StackoverflowとHTMLPurifierのドキュメントを検索しましたが、唯一の解決策は次のようです。

$config->set('HTML.Allowed', 'p,b,a[href],i');

ただし、ホワイトリストを再定義したくないため、これは解決策ではありません(デフォルトのHTMLPurifier構成を信頼しているので、例外を追加したいだけです)。

4

3 に答える 3

5

同じ問題が見つかりました。唯一の解決策は、ホワイトリストスタイルをHTMLピューリファイヤーの属性設定に貼り付けることでした。

ホワイトリストの設定は次のとおりです。

a.class,
a.href,
a.id,
a.name,
a.rev,
a.style,
a.title,
a.target,
a.rel,
abbr.title,
acronym.title,
blockquote.cite,
div.align,
div.style,
div.class,
div.id,
font.size,
font.color,
h1.style,
h2.style,
h3.style,
h4.style,
h5.style,
h6.style,
img.src,
img.alt,
img.title,
img.class,
img.align,
img.style,
img.height,
img.width,
li.style,
ol.style,
p.style,
span.style,
span.class,
span.id,
table.class,
table.id,
table.border,
table.cellpadding,
table.cellspacing,
table.style,
table.width,
td.abbr,
td.align,
td.class,
td.id,
td.colspan,
td.rowspan,
td.style,
td.valign,
tr.align,
tr.class,
tr.id,
tr.style,
tr.valign,
th.abbr,
th.align,
th.class,
th.id,
th.colspan,
th.rowspan,
th.style,
th.valign,
ul.style
于 2013-05-28T14:49:20.883 に答える
3

このコード:

<?php

require('purifier/library/HTMLPurifier.auto.php');

$html = "<img width='200' height='200' src='test.jpg' alt='bla>";
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
echo $purifier->purify($html) . "\n";

$html = "<table width='100'><tr><td>test</td></tr></table>";
echo $purifier->purify($html) . "\n";

?>

この出力を生成します:

<img width="200" height="200" src="test.jpg" alt="bla" />
<table width="100"><tr><td>test</td></tr></table>

php5.3.10およびHTMLPurifierバージョン4.4.0を使用します。したがって、これらの属性はデフォルトでは削除されません(HTMLPurifierのクリーンインストールを使用しています)

width / height属性を使用しているHTML要素はどれですか?

また、xhtml strictを使用すると、無効な属性が削除されることに注意してください。img要素とtable要素の幅と高さは、私が知る限り許可されていますが、小文字にする必要があります。画像要素の「width='100%'」を除く(rap-2-hのコメントの後に完全を期すために追加)

一般的に、許可された属性を追加するには、ホワイトリストの代わりにaddAttributeを使用します。

于 2012-07-10T11:17:09.700 に答える
0

魔法の引用符をオフにします。

于 2012-07-03T13:24:04.493 に答える