angular-ui-notification 的所有版本都存在 XSS 漏洞,因为该库没有对用户提供的输入进行转义。
为了安全使用该库,强烈建议对传递给该库的参数进行转义/编码,例如以下方式:
private sanitizeHTML(str: string) {
return str.replace(/[^\w. ]/gi, (c) => `&#${c.charCodeAt(0)};`);
}
假设该库已经导入并被某个项目使用。该库的使用方式可能如下:
private showNotification(message: string, delay: number, type: NotificationType) {
this.Notification.clearAll();
this.Notification[type]({
message,
delay,
replaceMessage: true
});
}
如果前端直接将任何用户输入传递给 message 参数,任何 <script> 标签都足以执行 XSS 攻击。
简单的 <script>alert(1)</script> 就足够了。
Xh4H
该项目似乎不再维护,因此我强烈建议使用仍在维护的替代方案。