Javascript 强化扫描问题:分配新URL时出现跨站点脚本问题
在我的JavaScript代码中,我创建了一个URL来重定向我的页面。它工作正常,但当我通过强化扫描运行它时,它会给我以下错误: 方法reloadParentTab()将未验证的数据发送到web浏览器的第行(行号),这可能导致浏览器执行恶意代码 我添加了一个URL验证程序,并通过它运行了新创建的URL,但是错误仍然存在。 现在,这就是它现在的样子:Javascript 强化扫描问题:分配新URL时出现跨站点脚本问题,javascript,Javascript,在我的JavaScript代码中,我创建了一个URL来重定向我的页面。它工作正常,但当我通过强化扫描运行它时,它会给我以下错误: 方法reloadParentTab()将未验证的数据发送到web浏览器的第行(行号),这可能导致浏览器执行恶意代码 我添加了一个URL验证程序,并通过它运行了新创建的URL,但是错误仍然存在。 现在,这就是它现在的样子: //This is reloadParentTab function, mentioned above function reloadParentT
//This is reloadParentTab function, mentioned above
function reloadParentTab() {
if(window.opener && !window.opener.closed) { //checks if parent tab is present
//here we check a variable, irrelevant here, except that it decides whether we
//run window.opener.location.reload() or specify the URL, which is what the scan
//complains about
if (someTriggerValid()) {
var href = window.opener.location.href; //This is the source
if (validURL(href)) { // running the validator
//building the new URL
var newHref = href.substring(0, href.indexOf("tracking.")) +
"tracking.base.open.request.do?dataObjectKey=object.dsaidCase&trackingId=" + caseId;
//running the new URL through the validator, just to show that I tried it both ways
if (validURL(newHref)) {
//this is "Sink", that's where unvalidated data is, supposedly, sent,
//although I am validating it
window.opener.location.href = newHref;
}
}
} else {
window.opener.location.reload();
}
}
}
//And this is the validator
function validURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
}
所以我的问题是:我遗漏了什么?我还需要做什么才能解决这个问题?欢迎提出任何意见。谢谢。您可以使用
URL
构造函数以更安全的方式实现validul
:函数validul(str){try{newurl(str);return true;}catch(err){return false;}}
。关于问题:扫描器不是完美的,所以可能是误报。在这种情况下,我可以像你建议的那样使验证器更安全,并确保扫描器将绕过它?真的有可能吗?有没有办法监视假阳性?扫描仪是否有可用漏洞?我不知道。应该是的,但我不确定。根据我的经验,他们经常出错,并给出很多误报。我不确定是否有办法观察假阳性,但通常你可以这样标记它,但准备好解释为什么它是假阳性。