Unsafe assignment to innerHTML

I have developed an add-on that adds a tooltip button in webpages for performing a search on social media websites.

Till now I used to have standard text in the button using the following code:

myVariable.innerHTML = "My text";

but I decided to release an updated version that also has localization:

myVariable.innerHTML = browser.i18n.getMessage("myText");

Since introducing the update I get the following warning during verification:

Unsafe assignment to innerHTML
Warning: Due to both security and performance concerns, this may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation.

Is there a workaround? Is there a way to eliminate the warning or is it impossible to avoid it?

IIRC you’re supposed to use Node.textContent
i18n.getMessage() isn’t external content, but the same rules apply.


4 Likes

I just uploaded a newer version of the add-on and I can assure you that you remember correctly!

Using Node.textContent made the warning vanish.