I am using DOMPurify to sanitize HTML to prevent XSS.
const sanitizedHtml = DOMPurify.sanitize(htmlString);
The the problem is by default DOMPurify doesn't honor attributes of HTML tags. In my case, I have an anchor element with target
attribute and that sanitized HTML removes the target
attribute.
From the documentation I found that the following code fix this issue:
const sanitizedHtml = DOMPurify.sanitize(htmlString, { ADD_ATTR: ['target'] });
However, my question is that if DOMPurify is removing all the attributes then there has to be some reason behind that. So if I allow some specific attribute as mentioned above, am I opening up any security risk (of XSS attack)?