I am trying to fix an XSS issue on a website, where a user provided link is sent server side, then rendered back into the webpage. An XSS attack can be performed where attacker's link will close out the HTML tag, by attaching something like this to the end of it:
"/><img+src/onerror%3d'alert(document.domain)'><"
I am experimenting with the OWASP Java HTML Sanitizer Library but can't get it to work.
It seems to break the link. For example, if I input this link to the LINKS
default policy, it breaks it:
Before: https://www.google.com/search?client=firefox-b-d&q=xss+encoding+url
After: https://www.google.com/search?client=firefox-b-d&q=xss+encoding+url
If I paste the link after encoding into the browser, it will not direct me straight to the google search.
I feel that I am misunderstanding something how XSS attacks work on URLs, and would appreciate help understanding why the sanitizer doesn't work as I expect. I would expect the sanitizer to encode characters like '<' and '"', but not to encode characters like an '='.