I have written a micro-templating utility that uses innerHTML to inject html fragments in a Web page, based on user input (either plain text strings or html strings).
My main concern is the risk of malicious script injection. The script could be injected via a script tag, or in an inline event (img onload, div onmouseover for example).
Is there a way to sanitize the html string to prevent such injections? Also, are there other script injection methods I should be aware of?
scripttags isn't enough if you want to prevent malicious users from doing malicious things. For example,<a href="http://yoursite.org" onclick="javascript:window.open('http://malicious.example.org')">An innocent looking link!</a>doesn't use ascripttag at all and is just as nasty.document.createTextNode()handles all these cases, and displays the tags literally, so they do not function.