首页 > 解决方案 > iframe 内的资源 URL 上下文中使用的不安全值

问题描述

我正在尝试在 Angular 应用程序中嵌入 iframe。

嵌入页面来自外部 URL,因此我必须使用 DomSanitizer 才能绕过安全信任资源 url:

    this.route.paramMap.pipe(
      map(params => params.get('projectName')),
      switchMap(projectName => retreiveUrlFunction()),
      map(url => this.sanitizer.bypassSecurityTrustResourceUrl(url) as string)
    ).subscribe(url => this.embedUrl = url)
<iframe [src]="embedUrl" width=770 height=500 style="border: 0; box-shadow: 5px 5px 56px 0px rgba(0,0,0,0.25);"></iframe>

这样做会加载 Iframe,但 Iframe 本身包含需要绕过安全信任的资源 URL。

我犯了同样的错误 :

Error: unsafe value used in a resource URL context (see https://g.co/ng/security#xss)

一个相对于 Iframe 中加载的所有脚本:

Refused to load the script 'https://a.bigbrain.me/bigbrain-1.0.min.js?v=1' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' http://localhost:8080 *.lvh.me:* https://realize.io https://dapulse.com https://mondaystaging.com https://itsmonday.com https://monday.com https://assets.zendesk.com https://cdn.actionbar.io....

我怎样才能完全绕过安全性?

标签: javascripthtmlangulariframe

解决方案


推荐阅读