【问题标题】:unsafe value used in a resource URL context资源 URL 上下文中使用的不安全值
【发布时间】:2018-11-17 16:54:29
【问题描述】:

我是 Angular 6 的新手,我收到了这个错误:

"在资源 URL 上下文中使用的不安全值(参见 http://g.co/ng/security#xss)"

我已经搜索了分配,发现要解决这个问题需要创建一个角度管道,我做了并创建了新管道,然后在 html 中更改了代码,但问题仍然存在,任何人都可以指导我吗?

创建新管道后更改 Iframe 代码如下所示:

 <iframe src="http://localhost:8087/bim/api/v1/dashboardTree/{{companyId}} |safe"></iframe>

管道的代码:

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Pipe({
  name: 'tree'
})
export class TreePipe implements PipeTransform {

  constructor(private sanitizer: DomSanitizer) {}

  transform(url) {
    return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}

【问题讨论】:

    标签: node.js angular angular6


    【解决方案1】:

    src 属性是一个字符串,管道不在那里评估。为了将其作为表达式进行评估,它应该是:

    <iframe [src]="('http://localhost:8087/bim/api/v1/dashboardTree/' + companyId) | safe"></iframe>
    

    另外,还有一个不一致的地方,管道在一个地方是safe,而在另一个地方是tree

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多