我正在我的 Express 应用程序上进行 nessus 测试
这是我得到的
基于每种方法的测试:
我做了一些搜索,实际上最终来到了这里。禁用 HTTP 方法、TRACK TRACE 等 https://stackoverflow.com/questions/40303607/nodejs-http-server-disable-http-methods-track-trace-etc
解决方案
const allowedMethods = ['GET','HEAD','POST'];
function onrequest(req, res) {
if (!allowedMethods.includes(req.method))
return res.end(405, 'Method Not Allowed');
// ...
}
但是我不明白如何使用该解决方案,
@kiksy 评论说:This method would sit in your front controller. eg from here: expressjs.com/en/starter/hello-world.html You would add it to line 3
但第 3 行是"const port = 3000"
这让我很困惑
有人可以帮我吗
仅供参考,我无法发表评论,因为我没有 50 名代表
该注释本质上是说您可以将其添加到任何路由中,并且检查每个请求的传入方法以查看它是否是白名单中的 HTTP 方法之一,如果不是,您将返回一个405
让用户知道他们尝试使用的方法不受支持。
您可以使用中间件来覆盖所有请求。
const allowedMethods = ['GET', 'HEAD', 'POST']
app.use((req, res, next) => {
if (!allowedMethods.includes(req.method)) return res.end(405, 'Method Not Allowed')
return next()
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)