Angular translate指令vs filter:XSS可能吗?

Ani*_*nha 7 xss angularjs angular-translate

我有一个翻译密钥,实际上是一个HTML代码,编码和未编码.

   $scope.translations = {
    "html_code" : "<script>alert('Alert!');</script>",
    "html_code_full" : "<script>alert('Alert!');</script>",
    "greeting" : "Welcome!" 
  }
Run Code Online (Sandbox Code Playgroud)

当我使用这些值来显示视图中的翻译文本时,我使用两种方法:

  1. 作为指示 <span translate>{{translations.html_code}}</span>
  2. 作为过滤器 {{translations.html_code|translate}}

我尝试相同的translations.html_code_full.这是视图的代码:

translations.html_code = {{translations.html_code|translate}}
translations.html_code = <span translate>{{translations.html_code}}</span>

translations.html_code_full = {{translations.html_code_full|translate}}
translations.html_code_full = <span translate>{{translations.html_code_full}}</span>
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出:

translations.html_code = &lt;script&gt;alert('Alert!');&lt;/script&gt; 
translations.html_code = <script>alert('Alert!');</script> 


translations.html_code_full = <script>alert('Alert!');</script> 
translations.html_code_full =
Run Code Online (Sandbox Code Playgroud)

很明显,指令实现是将转换键编码为HTML,但过滤器不是.为什么指令与过滤器实现之间的输出存在差异?如果它呈现HTML,为什么我没有收到警报?

这是我为演示创建的插件.

geo*_*awg 1

AngularJS 框架正在保护您的应用程序免受 XSS 攻击。

截至 2007 年,赛门铁克记录的所有安全漏洞中,大约 84% 是由网站上执行的跨站点脚本造成的。

--维基百科 - 跨站脚本

那么你真正想做什么?也许我们可以向您展示如何安全地做到这一点。

  • 我有同样的问题。我可以使用翻译指令在我的应用程序中本地重现 css 攻击,而过滤器似乎是安全的 - 但如果我尝试制作一个反映此问题的 plunkr,则 css 不起作用,并且脚本会被正确过滤掉。尝试了 ng-translate 的 2.8.1 和 2.9.0 版本。尝试了不同的消毒策略,但都不起作用。我想知道翻译指令是否存在安全漏洞。 (2认同)