如何撤消绕过SecuritySecurityTrustHtml,即将SafeValue转换回字符串

Joh*_*kel 2 html-sanitizing angular

我正在生成html,并使用将其插入到我的网页中

let data = '<font color=blue>hello world</font>';
this.safevalue = this.domSanitizer.bypassSecurityTrustHtml(data);
Run Code Online (Sandbox Code Playgroud)

在我的代码的其他地方,我想将安全值转换回字符串,所以我尝试了这个...

data = this.safevalue.toString();
Run Code Online (Sandbox Code Playgroud)

但这会将数据设置为这样的字符串...

'SafeValue must use [property]=binding: (see http://g.co/ng/security#xss)'
Run Code Online (Sandbox Code Playgroud)

这没有帮助

DeB*_*ges 6

我不知道您是否已经找到了解决方法,但是,如果您只想要原始值,请标记为安全:

var yourString = this.domSanitizer.sanitize(SecurityContext.HTML, data)
Run Code Online (Sandbox Code Playgroud)