Tej*_*ggi 5 javascript xss mean-stack
我试图使用CheckMarx验证我的代码,但被困在几个无法找到修复程序的漏洞中。以下是引发漏洞的代码行。
window.location.href = url + "?"+"appPageId="+
$rootScope.selectedContext.defaultAppPageId + "&hierarchyId="+
$rootScope.defaultHierarchyId
Run Code Online (Sandbox Code Playgroud)
我试图通过编码来修复它,如下所示
var redirectUrl = url + "?"+"appPageId="+
$rootScope.selectedContext.defaultAppPageId + "&hierarchyId="+
$rootScope.defaultHierarchyId
window.location.href = encodeURI(redirectUrl)
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的问题。无论如何,是否有解决此客户端DOM开放重定向漏洞的方法?
另外,我在以下行中遇到了Reflected XSS问题
res.send("The Context
"+req.params.contextName+" has restricted access. Please request
access to this page");
Run Code Online (Sandbox Code Playgroud)
可能是因为我正在使用res.send。我猜这也将按照与上述问题相同的方式解决。
任何有关相同的帮助将不胜感激。
我相信 Checkmarx 在流程中首先将 url 变量视为任意的,这就是为什么它将其视为客户端 DOM 开放重定向漏洞。如果您不需要任意值,可以尝试在 url 前添加硬编码值。
if(isNaN($rootScope.selectedContext.defaultAppPageId) || isNaN($rootScope.defaultHierarchyId)) {
return
}
var redirectUrl = "https://stackoverflow.com?" + "appPageId=" +
$rootScope.selectedContext.defaultAppPageId + "&hierarchyId="+
$rootScope.defaultHierarchyId
window.location.href = encodeURI(redirectUrl)
Run Code Online (Sandbox Code Playgroud)
对于 XSS 漏洞,它很可能被视为误报,因为 Angular 会清理并转义不受信任的值。但是,您不能总是相信视图引擎会完成其工作,因此如果您确实想要显式修复,您可能需要使用 html 编码库(找到一个合适的库,这只是一个示例):
var htmlencode = require('htmlencode');
res.send("The Context"+ htmlencode.htmlEncode(req.params.contextName) + " has restricted access. Please request access to this page");
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!