I have below javascript function in same jsp file which open a new window based on the parameter passed in the link. It was told to me that I need to encode to prevent XSS attack.
<script language="JavaScript">function openDocWindow(report,index,reportType) {
link = '/ocs/jsp/single_report_frameset.jsp?
report_id='+index+'&id=13740995910316prfXwysgrSGk2Strm7pvxC'+
index+'&startCount=0'+'&enclosure_id='+index;
parent.window.open(link,'detail','width=640,height=480,toolbar=no,
location=no,directories=no,status=yes,menubar=no,scrollbars=
yes,resizable=yes,alwaysRaised=yes');
return;
}
So I thought to encode link veriable using encodeURIComponent() or encodeURI() but I need to know if I do like below then will it be able to prevent XSS attack?
parent.window.open(encodeURIComponent(link),'detail','width=640,height=480,toolbar=no,
location=no,directories=no,status=yes,menubar=no,scrollbars=
yes,resizable=yes,alwaysRaised=yes');
return;
Thanks for your help!