问题标签 [html-sanitizing]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
658 浏览

django - HTML:清理一组标签,但允许所有标签进入 blocks

0 投票
3 回答
18056 浏览

javascript - Javascript 清理:插入可能的 XSS html 字符串的最安全方法

目前我正在将此方法与 jQuery 解决方案一起使用,以从可能的 XSS 攻击中清除字符串。

但我有一种感觉,它不够安全。我想念什么吗?

我在这里尝试了 phpjs 项目中的 htmlentities:http://phpjs.org/functions/htmlentities:425 /

但它有点错误并返回一些额外的特殊符号。也许它是一个旧版本?

例如:

产生:

但应该是:

你如何通过javascript处理这个?

0 投票
1 回答
1287 浏览

java - 使用 owasp-java-html-sanitizer 提取链接

我计划使用 owasp-java-html-sanitizer 对用户生成的 html 执行一些任务。

我想从 html 字符串中提取 URL 列表。

我还想确保所有链接的目标都设置为“_blank”,这似乎与HtmlPolicyBuilder.requireRelNofollowOnLinks配置相似。(完毕)


这增加target="_blank"了链接,不确定它是完成它的最佳方式。

这也提取了 URL:

0 投票
1 回答
1599 浏览

php - htmlspecialchars 导致文本消失

我遇到了一个导致 htmlspecialchars() 返回零长度字符串的特定字符串(它不是完全可打印的,但您可以在下面看到它)。有什么办法可以解决这个问题吗?

输出:

0 投票
1 回答
565 浏览

html-sanitizing - 谷歌卡哈没有建立

我在哪里可以下载文件 html-css-sanitizer-minified.js?我宁愿下载文件也不愿自己构建 caja。原因:我尝试构建 caja 并得到以下错误。任何线索?

谢谢

0 投票
2 回答
3977 浏览

python - 'list' 对象在 Python 的 BeautifulSoup renderContents 中没有属性 'items'

为了从输入中删除不需要的/不安全的标签和属性,我使用了下面的代码(几乎完全由http://djangosnippets.org/snippets/1655/提供):

它适用于不需要的或列入白名单的标签、未列入白名单的属性,甚至是格式错误的 html。但是,如果存在任何列入白名单的属性,则会引发

在最后一行,这对我没有多大帮助。type(soup)<class 'bs4.BeautifulSoup'>它是否引发错误,所以我不知道它指的是什么。

0 投票
3 回答
4361 浏览

ruby-on-rails-3 - Rails 3提交标签+ html_safe

这行代码有什么问题?

这实际上产生:

在此处输入图像描述

显然我的 html_safe 调用没有做任何事情。

背景:

我正在使用Twitter BootstrapFont Awesome,我实际上是在尝试实现一个带有图标的提交按钮。

0 投票
1 回答
236 浏览

firefox - 安全地使用远程 HTML

我被要求通过parseHTMLMozilla 插件审阅者调用的函数将一些 html 从我的服务器发送到我的 Firefox 插件。有问题的方法记录在这个 XUL 学校教程中。

然而,在我的内容脚本中,typeof parseHTML == "undefined". 我相信这是因为我的插件是使用插件 SDK 构建的,而不是 XUL。

用SDK构建的附加组件无权访问此方法是否正确?SDK中是否有等效方法?

0 投票
2 回答
4036 浏览

ruby - Ruby Regex 捕获两个字符串之间的所有内容(包括)

我正在尝试清理一些 HTML 并删除一个标签(我真的很想避免使用 nokogiri 等)。因此,我想摆脱以下字符串:

这在我的字符串中只出现一次,我想找到一种方法来删除它。我试过想出一个正则表达式来捕获它,但我找不到一个有效的。

我已经尝试过/<div class="the_class">(.*)<\/div>/m并且有效,但它也会匹配并包含</div>文档中的任何其他标签,这是我不想要的。

关于如何解决这个问题的任何想法?

0 投票
1 回答
243 浏览

php - Why is the `NAME` attribute considered unsafe?

I'm passing user-generated HTML into a database and I'm trying to make sure that no malicious code is passed through. One of the steps I'm taking is to run passed code through pear's HTML_Safe class to remove vulnerable markup. However, one thing I've noticed is that the name attribute of submitted elements gets removed. Sure enough, when you look at the source code, name is one of the few attributes that's blacklisted by default:

http://pear.php.net/package/HTML_Safe/docs/latest/HTML_Safe/HTML_Safe.html#var$attributes

What's the danger in allowing users to pass values for name? How can values for name be used to nefarious ends? Any thoughts? If not, I'm tempted to modify the blacklist.