I have a XSS vurnerability in one of a html input field (<input type="text">
) which I wanted to take care of. The html input is for social media urls (for ex. Facebook, Linkedin, Jabber, Skype etc.) and is later displayed as: <a href=link>link</a>
.
There is no validation so users may input whatever they want. Then, when someone clicks the link in app and if there is dangerous javascript, it will be executed. What I decided to do is to escape these urls in output so they will not execute any javascript on click. I am using jsf as view and I couldn't find tool which would help me fix it properly.
Firstly, I wanted to do some basic url validation before saving users input but because of complexity of the urls (links may not start with protocol and it can may be any name because some of social media will have default address prefix (scheme) in system, for ex skype: for Skype, so urls may be like: linkedin.com/in/name or asdqwe) I had to abandon this idea.
What I tried to do is escape these urls with method StringEscapeUtils.escapeJavaScript
from apache.commons.lang
, but it is not preventing from every type of dangerous code, for example it will not prevent for inputing : javascript:alert(0);
so I am looking for a tool which could provide me escaping these url to completely or almost completely prevent from xss. Thank you for any help.