【发布时间】:2021-11-03 23:25:24
【问题描述】:
我在 express 中间件中使用 axios lib 从 API 获取响应
router.post(someurl,req,res)
{
axios
.get(someurl)
.then((response=>{
**res.send(response.data);**//contains array object which would be send as a JSON response by send()
}
}
Checkmarx 扫描将此报告为不受信任的数据,并且可能反映了 XSS 攻击,因为 response.data 可能容易受到攻击。 它说:应用程序 .then() 使用 send() 将不受信任的数据嵌入到生成的输出中,并且数据直接嵌入到输出中,而无需进行适当的清理或编码,从而使攻击者能够注入恶意代码。
如何解决这个问题,因为 UI 将数组响应呈现给呈现列表。 或者如果我们可以编码可以作为响应返回的数组对象?
【问题讨论】:
-
我也遇到了同样的问题,你有解决办法吗?请推荐!
-
我使用了 JSON.stringify(response.data) 它对我有用。
-
我在这条线上遇到错误 const countries = JSON.stringify(this.props.countries);
标签: javascript node.js reactjs express checkmarx