是否可以让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) 我的想法是以某种方式缩小服务器端的HTML代码,因此客户端接收的字节数更少.
"缩小"是什么意思?
没有拉链.更像是,例如,jQuery创建者使用.min .js版本.换句话说,我需要删除不必要的空格和换行符,但我不能删除那么多的HTML更改表示(例如删除段落中实际单词之间的空格).
有没有可以做到的工具?我知道有HtmlPurifier.它能够做到吗?还有其他选择吗?
PS请不要提供正则表达式.我知道只有Chuck Norris可以用它们解析HTML.=]
如何允许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)
这可能吗?
是否有一个全面的Html清理器/ Anti-Xss库用于.NET,也有一个定义的白名单.我知道微软Anti-Xss是一个很好的起点,但它需要一个很好的白名单,允许html标签和CSS.有谁知道什么?
我正在使用javascript WYSIWYG编辑器处理来自公众的用户输入,我正计划使用htmlpurifier来清理文本.
我认为在输入上使用htmlpurifier,将清理后的输入存储在数据库中,然后输出它而不进一步转义/过滤就足够了.但我听到其他意见,你应该总是逃避输出.
如果我已经清理了输入,有人可以解释为什么我需要清理输出吗?
这是我想在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 …
我试图让一些人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: …
两者的优点/缺点是什么?
您将使用哪一个来过滤用户在网站上发布的评论?
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 很弱。:(
我看到了Kohana框架,允许用户选择使用HTMLPurifier来对抗任何可能的XSS攻击.
我认为HTMLPurifier旨在允许HTML的标准兼容输出.
它是否有助于避免XSS攻击100%或可能在很大程度上?或者你会建议其他的东西.
谢谢
htmlpurifier ×10
php ×6
html ×3
filter ×2
.net ×1
embed ×1
filtering ×1
html-email ×1
html-parsing ×1
iframe ×1
io ×1
javascript ×1
min ×1
minify ×1
object ×1
webmail ×1