I am looking at the option to clean the URL for the possible XSS issue. Here is my high level of workflow.
- We keep trek of the user and the page journey using the analytics.
- To send the data to analytics, we use the in page DOM injection based on the java script provided by the analytics team.
- As part of the trekking, we need to send the page URI, here is how we are doing that in the
jsp
page.
data["pageName"]="${sanitizeInput(requestScope['javax.servlet.forward.request_uri'])}";
This is working fine and data is passed to the analytics without any issue except when someone try to pass some script data in the URL. I am finding lot of request with similar pattern
https://domainname/'%3bfunc(document.cookie)%3b'
The pattern is same, where the system is trying to send similar values. (passing the script in ''). Though most of it is taken care at the CDN level and we are redirecting the user to the 404 page but I still want to handle this while writing the page name on the 4040 page as well.
As an additional information sanitizeInput
is using Jsoup
internally.Can someone help me with the following questions
- What is the best way to handle similar issue?
- Is there a better option to remove/ clean the URL before using the value in the JSP?
- Any API/ library which can help me to clean the URL before using the value
Any other options to handle it correctly?