我有一个用 Html 响应的 Api。由于 xss,我不想完全信任内容。
但有时我会根据白名单在我想要信任的响应中包含 iframe。
我知道这种bypassSecurityTrustHtml()
可能性,但我没有找到如何部分信任 Html。
例如:Api 响应
<p>Some test text<br class='autobr' />\n<strong>some
more</strong></p>\n<iframe
src=\"https://player.vimeo.com/video/289729765\" width=\"640\"
height=\"360\" frameborder=\"0\" webkitallowfullscreen
mozallowfullscreen allowfullscreen></iframe>\n<p><a
href=\"https://vimeo.com/289729765\">Mike Hopkins: The
Backyard</a> from <a
href=\"https://vimeo.com/diamondback\">Diamondback Bicycles</a>
on <a href=\"https://vimeo.com\">Vimeo</a>.</p>\n<p>and the
end</p>
然后我只想信任 iframe 并像这样显示整个文本:<div innerHtml="myResponse"></div>
我尝试提取 iframe,信任它,然后将其替换为受信任的SafeHtml
. 那没有用。是否有可能部分绕过SecurityTrustHtml()?
我正在使用Angular 6 ...
谢谢你的帮助