加载本地 css 文件时在资源 URL 上下文中使用的不安全值
unsafe value used in a resource URL context when loading local css file
我想知道是否有人可以解释 Angular2 中 Dom Sanitisation 在我的案例中的含义:
img 的情况很好,它只是 werks。样式表将触发标题中的错误。
什么什么?为什么?有人吗?
<img *ngIf="css" [src]="css" style="height:64px;margin-right:8px">
<link *ngIf="css" rel="stylesheet" [href]="css">
更新
DomSanitizationService
将在 RC.6
中重命名为 DomSanitizer
原创
图像是安全的。有一个 <img>
标签,它显示图像数据,仅此而已。 CSS 可以做得更多。 CSS 甚至可以添加 HTML https://developer.mozilla.org/en/docs/Web/CSS/::after 这是非常不安全的。
要明确允许 "unsafe" 内容,请使用消毒剂
import {DomSanitizationService} from '@angular/platform-browser';
return this.sanitizer.bypassSecurityTrustStyle(style);
或使用消毒剂提供的其他方法之一https://angular.io/docs/js/latest/api/platform-browser/index/DomSanitizationService-class.html
另请参阅 以获取允许直接在绑定中应用 bypassSecurityXxx
方法的示例管道。
我想知道是否有人可以解释 Angular2 中 Dom Sanitisation 在我的案例中的含义:
img 的情况很好,它只是 werks。样式表将触发标题中的错误。 什么什么?为什么?有人吗?
<img *ngIf="css" [src]="css" style="height:64px;margin-right:8px">
<link *ngIf="css" rel="stylesheet" [href]="css">
更新
DomSanitizationService
将在 RC.6
DomSanitizer
原创
图像是安全的。有一个 <img>
标签,它显示图像数据,仅此而已。 CSS 可以做得更多。 CSS 甚至可以添加 HTML https://developer.mozilla.org/en/docs/Web/CSS/::after 这是非常不安全的。
要明确允许 "unsafe" 内容,请使用消毒剂
import {DomSanitizationService} from '@angular/platform-browser';
return this.sanitizer.bypassSecurityTrustStyle(style);
或使用消毒剂提供的其他方法之一https://angular.io/docs/js/latest/api/platform-browser/index/DomSanitizationService-class.html
另请参阅 bypassSecurityXxx
方法的示例管道。