角度2处理梯度是不安全的

dav*_*vid 7 css xss gradient angular

我正在尝试动态地在组件上设置渐变,并收到以下警告:

WARNING: sanitizing unsafe style value linear-gradient(#000,#00f) (see http://g.co/ng/security#xss).

这是一个最小的再现:

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  template: '<h1 [style.background]="(\'linear-gradient(#000,#00f)\')">My First Angular 2 App</h1>'
})
export class AppComponent {}
Run Code Online (Sandbox Code Playgroud)

我的谷歌搜索告诉我使用,bypassSecurityTrustStyle但在我知道之前我不喜欢这样做

  1. 为什么线性梯度被认为是不安全的?
  2. 这是预期的行为还是只是当前版本的Angular 2的错误.
  3. 如果没有被认为是不安全的,有没有更好的方法呢?

这必须是动态的,因为我正在以编程方式构建渐变字符串.我不能为此使用css类.