【问题标题】:SafeValue must use [property]=binding:SafeValue 必须使用 [property]=binding:
【发布时间】:2016-09-15 17:52:25
【问题描述】:

我的输入中出现以下错误:

SafeValue must use [property]=binding: http://www.myurl.com (see http://g.co/ng/security#xss)

我在我的组件中做了:

this.myInputURL = this.sanitizer.bypassSecurityTrustUrl('http://www.myurl.com');

在我的模板中:

Share URL: <md-input [value]="myInputURL" type="text"></md-input>

怎么了?

【问题讨论】:

  • 你只想在输入控件中显示它?它说,将它注入 DOM 是不安全的
  • 嗯.. 我没有看到任何其他选项允许快速轻松地复制链接 URL
  • 也许您缺少正确的声明 public myInputURL: SafeResourceUrl;。有关详细信息,请参阅下面的答案。

标签: angular


【解决方案1】:

改变这个

this.sanitizer.bypassSecurityTrustUrl('http://www.myurl.com');

this.sanitizer.bypassSecurityTrustResourceUrl('http://www.myurl.com');

两个选项的区别

绕过SecurityTrustUrl

绕过安全性并相信给定的值是一个安全样式的 URL,即可以在超链接或 . source angular.io

绕过SecurityTrustResourceUrl

绕过安全性并相信给定的值是一个安全的资源 URL,即一个可用于加载可执行代码的位置,例如 或 。 source angular.io

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。虽然我没有完全阅读文档,但组件内的清理似乎没有按预期工作。

    什么是有效的,但是在模板中进行清理。例如:

    <object type="text/html" [data]="sanitizer.bypassSecurityTrustResourceUrl(app.url)" ngDraggable></object>

    其中app.url在组件中声明:

    public url: SafeResourceUrl = "http://example.com"

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      我也发生了同样的事情。这是因为跨域限制。只需使用嵌入版本链接 https://www.youtube.com/embed/video-ID 而不是常规网址 https://www.youtube.com/watch?v=Video-ID

      是的,您仍然会收到相同的警告,但您现在可以忽略它,因为一切都会按预期工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-06
        • 2018-06-05
        • 1970-01-01
        • 2018-01-03
        • 2021-04-08
        • 2018-09-20
        相关资源
        最近更新 更多