标签: htmlpurifier

带有html5 doctype的htmlpurifier

是否可以让htmlpurifier使用html5 doctype?

此处的文档指出您可以使用以下内容更改doctype和encoding:

<?php
    require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';

    $config = HTMLPurifier_Config::createDefault();
    $config->set('Core', 'Encoding', 'ISO-8859-1'); // replace with your encoding
    $config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); // replace with your doctype
    $purifier = new HTMLPurifier($config);

    $clean_html = $purifier->purify($dirty_html);
?>
Run Code Online (Sandbox Code Playgroud)

但是在安装说明中,这里说明支持的doctypes是:

256 Other supported doctypes include:
257
258     * HTML 4.01 Strict
259     * HTML 4.01 Transitional
260     * XHTML 1.0 Strict
261     * XHTML 1.0 Transitional
262     * XHTML 1.1
Run Code Online (Sandbox Code Playgroud)

是否可以执行以下操作以允许html5 doctype?

<?php
        require_once '/path/to/htmlpurifier/library/HTMLPurifier.auto.php';

        $config = HTMLPurifier_Config::createDefault();
        $config->set('Core', 'Encoding', 'UTF-8'); …
Run Code Online (Sandbox Code Playgroud)

php htmlpurifier

8
推荐指数
2
解决办法
4143
查看次数

如何缩小HTML代码?

我的想法是以某种方式缩小服务器端的HTML代码,因此客户端接收的字节数更少.

"缩小"是什么意思?

没有拉链.更像是,例如,jQuery创建者使用.min .js版本.换句话说,我需要删除不必要的空格和换行符,但我不能删除那么多的HTML更改表示(例如删除段落中实际单词之间的空格).

有没有可以做到的工具?我知道有HtmlPurifier.它能够做到吗?还有其他选择吗?

PS请不要提供正则表达式.我知道只有Chuck Norris可以用它们解析HTML.=]

html min minify html-parsing htmlpurifier

8
推荐指数
2
解决办法
1万
查看次数

如何配置HTML Purifier以允许图像src的数据URI?

如何允许base64数据用于图像标记的src属性?我看到这样的代码:

$config->set('URI.AllowedSchemes', array('http' => true, 'https' => true, 'mailto' => true, 'ftp' => true, 'nntp' => true, 'news' => true, 'data' => true));
Run Code Online (Sandbox Code Playgroud)

在这种情况下,是否data => true允许base64?如果是这样,我怎么能只允许base64数据用于img标签的src属性?(我不想在其他情况下允许数据URI.)

我想过做的事情:

$ def-> addAttribute ('a', 'target', 'Enum # _blank, _self, _target, _top');     
Run Code Online (Sandbox Code Playgroud)

但在我的情况下像这样:

$ def-> addAtribute ('img', 'src', 'Enum # data, http, https, ...);
Run Code Online (Sandbox Code Playgroud)

这可能吗?

php htmlpurifier rich-text-editor

8
推荐指数
1
解决办法
2112
查看次数

是否有HtmlPurifier的.NET实现(php)

是否有一个全面的Html清理器/ Anti-Xss库用于.NET,也有一个定义的白名单.我知道微软Anti-Xss是一个很好的起点,但它需要一个很好的白名单,允许html标签和CSS.有谁知道什么?

.net htmlpurifier

7
推荐指数
1
解决办法
3251
查看次数

使用htmlpurifier进行输入或输出转义/过滤

我正在使用javascript WYSIWYG编辑器处理来自公众的用户输入,我正计划使用htmlpurifier来清理文本.

我认为在输入上使用htmlpurifier,将清理后的输入存储在数据库中,然后输出它而不进一步转义/过滤就足够了.但我听到其他意见,你应该总是逃避输出.

如果我已经清理了输入,有人可以解释为什么我需要清理输出吗?

php io filtering htmlpurifier

7
推荐指数
1
解决办法
1877
查看次数

如何在HTMLPurifier中允许脚本,对象,参数,嵌入和iframe标记?

这是我想在HTMLPurifier中允许的一种特殊的标签组合,但似乎无法使组合起作用.

我可以让脚本标签工作,但然后嵌入标签被删除(我使用HTML.Trusted = true启用脚本标签).当我重新嵌入标签时,脚本标签被删除(我删除了HTML.Trusted).以下是我的配置:

        $config->set('HTML.Trusted', true);
        $config->set('HTML.SafeEmbed', true);
        $config->set('HTML.SafeObject', true);
        $config->set('Output.FlashCompat', true);
Run Code Online (Sandbox Code Playgroud)

我甚至尝试添加以下内容,这使事情变得更糟:

        $config->set('HTML.Allowed', 'object[width|height|data],param[name|value],embed[src|type|allowscriptaccess|allowfullscreen|width|height],script[src|type]');
Run Code Online (Sandbox Code Playgroud)

而且,无论如何,我似乎无法让iframe工作.我尝试添加:

        $config->set('HTML.DefinitionID', 'enduser-customize.html iframe');
        $config->set('HTML.DefinitionRev', 1);
        $config->set('Cache.DefinitionImpl', null); // remove this later!
        $def = $config->getHTMLDefinition(true);
        $iframe = $def->addElement(
            'iframe',   // name
            'Block',  // content set
            'Empty', // allowed children
            'Common', // attribute collection
            array( // attributes
                'src*' => 'URI#embedded',
                'width' => 'Pixels#1000',
                'height' => 'Pixels#1000',
                'frameborder=' => 'Number',
                'name' => 'ID',
            )
        );
        $iframe->excludes = array('iframe' => true);
Run Code Online (Sandbox Code Playgroud)

任何有关使整个组合工作的帮助,甚至是带有object/param和embed的脚本标签都会非常感激!!!

哦,是的,这显然不适合所有用户,只是"特殊"用户.

谢谢!

PS - 请不要将我链接到http://htmlpurifier.org/docs/enduser-customize.html …

javascript embed iframe object htmlpurifier

7
推荐指数
1
解决办法
4532
查看次数

HtmlPurifier - 允许数据属性

我试图让一些人data-attribute使用htmlPurifier,span但我没办法......

我有这个字符串:

<p>
    <span data-time-start="1" data-time-end="5" id="5">
       <word class="word">My</word>
       <word class="word">Name</word>
    </span>
    <span data-time-start="6" data-time-end="15" id="88">
       <word class="word">Is</word>
       <word class="word">Zooboo</word>
    </span>
<p>
Run Code Online (Sandbox Code Playgroud)

我的htmlpurifier配置:

$this->HTMLpurifierConfigInverseTransform = \HTMLPurifier_Config::createDefault();
$this->HTMLpurifierConfigInverseTransform->set('HTML.Allowed', 'span,u,strong,em');
$this->HTMLpurifierConfigInverseTransform->set('HTML.ForbiddenElements', 'word,p');
$this->HTMLpurifierConfigInverseTransform->set('CSS.AllowedProperties', 'font-weight, font-style, text-decoration');
$this->HTMLpurifierConfigInverseTransform->set('AutoFormat.RemoveEmpty', true);
Run Code Online (Sandbox Code Playgroud)

$value像这样净化我:

$purifier = new \HTMLPurifier($this->HTMLpurifierConfigInverseTransform);
var_dump($purifier->purify($value));die;
Run Code Online (Sandbox Code Playgroud)

得到这个:

<span>My Name</span><span>Is Zoobo</span>
Run Code Online (Sandbox Code Playgroud)

但是,如何保护我的数据属性id,data-time-start,data-time-end在我的span

我需要这个:

<span data-time-start="1" data-time-end="5" id="5">My Name</span data-time-start="6" data-time-end="15" id="88"><span>Is Zoobo</span>
Run Code Online (Sandbox Code Playgroud)

我试着用这个配置测试:

$this->HTMLpurifierConfigInverseTransform->set('HTML.Allowed', 'span[data-time-start],u,strong,em');
Run Code Online (Sandbox Code Playgroud)

但错误信息:

用户警告:不支持元素"span"中的属性"data-time-start"(有关实现此信息的信息,请参阅支持论坛)

谢谢你的帮助 !!

编辑1

我尝试在这个代码行的firdt时间允许ID: …

php filter htmlpurifier

7
推荐指数
1
解决办法
2490
查看次数

HTMLPurifier与Kses

两者的优点/缺点是什么?

您将使用哪一个来过滤用户在网站上发布的评论?

html php filter htmlpurifier

6
推荐指数
2
解决办法
2509
查看次数

网络邮件:HTML 标头

HTML 电子邮件是一个复杂的野兽。决定发送什么(作为发件人)和显示什么(作为收件人)是很棘手的,而且有潜在的危险。

在收件人方面,我们有网络邮件常规电子邮件客户端。出于我的目的,我认为“网络邮件”是任何将 HTML 电子邮件显示为本身是 HTML 的一部分的任何内容,而常规电子邮件客户端则是任何在不同上下文中显示 HTML 电子邮件的内容(例如操作系统和特定于程序的 GUI)。

webmail 应该如何处理电子邮件中的 HTML 标头(<head><title><meta>、 ...)?
某处是否有规范,是作为实际标准还是事实上的标准?

我提出这个问题的动机是我们使用HTML Purifier来清理我们的 HTML,如果它的Core.CollectErrors功能报告发生了变化,他们就会被报告。这种“报告”既必要……又令人沮丧。我们删除了一些报告的错误,认为对我们的目的来说无关紧要,但 HTML 标头标志着一个巨大的障碍:

有人可能会<link>在他们的电子邮件中使用,我们将删除。(HTML Purifier 适用于 HTML片段,而非完整文档)

使用<link>HTML 电子邮件之类的东西的愿望似乎确实存在,并且有很多电子邮件客户端<meta>在 HTML 标题(例如 Outlook)中发送-tags,但是如何处理这些事情?悄悄地剥离它们是否安全(就我们而言,这表示“非破坏性更改”)并在发送方确实破坏时将其归咎于众所周知的责任?这合理吗?有没有人以一种或其他方式决定过这一点?我的 google-fu 很弱。:(

webmail html-email htmlpurifier

6
推荐指数
1
解决办法
679
查看次数

HTMLPurifier真的是防弹吗?

我看到了Kohana框架,允许用户选择使用HTMLPurifier来对抗任何可能的XSS攻击.

我认为HTMLPurifier旨在允许HTML的标准兼容输出.

它是否有助于避免XSS攻击100%或可能在很大程度上?或者你会建议其他的东西.

谢谢

html php htmlpurifier

5
推荐指数
1
解决办法
905
查看次数