0
我在同一個jsp文件中具有下面的javascript函數,該函數根據鏈接中傳遞的參數打開一個新窗口。有人告訴我,我需要編碼以防止XSS攻擊。應使用哪種編碼
<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;
}
所以我認爲編碼鏈接veriable使用encodeURIComponent方法()或者是encodeURI(),但我需要知道,如果我不喜歡下面則,它才能防止XSS攻擊?
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;
感謝您的幫助!
感謝您的幫助。那我該如何預防XSS?我想使用ESAPI.encoder()。encodeForURL(String str),但我無法將鏈接變量作爲ESAPI方法的字符串參數傳遞。它說鏈接無法解決。我嘗試過使用ESAPI parent.window.open(ESAPI.encoder()。encodeForURL(link.toString()),'detail','width = 640,height = 480,toolbar = no,location = no,directories = no ,狀態=是,菜單欄=沒有,滾動條=是,可調整大小=是,alwaysRaised =是); –