【问题标题】:ngSanitize does not allow allow id attributengSanitize 不允许允许 id 属性
【发布时间】:2014-05-23 15:47:01
【问题描述】:

我正在使用ngBindHtml 显示来自(内部)CMS 的一些 HTML:

<span ng-bind-html="cmsHtml"></span>

HTML 包含一个带有id 属性的链接:

"<a id='fsgPdfLink' href='http://blah/download.pdf' target='_blank'>Click here to download the PDF</a>"

但是,我注意到在将链接写入页面之前,id 属性已被 angular 删除,因此呈现的只是:

<a href='http://blah/download.pdf' target='_blank'>Click here to download the PDF</a>

查看 ngSanitize 模块的来源,似乎由于某种原因 id 属性不在有效属性列表中:

https://github.com/angular/angular.js/blob/master/src/ngSanitize/sanitize.js#L206

  1. 不允许 id 属性的原因是什么?是否存在安全风险?
  2. 如果可能的话,我真的很想继续使用 ngBindHtml。是否有可以将安全标签添加到消毒剂列表的 API?还是我必须自己编辑源代码才能添加此标签?

【问题讨论】:

  • 我还没有完成绑定 HTML,但在我所做的研究中建议使用 $sce 服务,所以我打算使用 $sce.parseAsHtml,你有没有考虑过使用它与清理?

标签: angularjs ng-bind-html ngsanitize


【解决方案1】:

为了部分回答我自己的问题,似乎没有 API 可以更改内置白名单,如本公开问题中所述:

https://github.com/angular/angular.js/issues/5900

【讨论】:

    猜你喜欢
    • 2014-11-08
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多