在Heroku中完全禁用HTTP

sil*_*hil 7 security ssl heroku node.js express

我们有一个在Heroku中运行的node.js express应用程序.它处理身份验证,必须是高度安全的.

当我们收到HTTP请求时,我们强制重定向到HTTPS.但这似乎还不够.使用像sslstrip这样的工具,我们可以通过HTTP进行POST.

目前唯一的解决方案似乎是在Heroku上完全禁用HTTP.

怎么做?还有其他建议吗?

Rya*_*yan 7

根据OWASP,您不应该从HTTP重定向到HTTPS.有关详细信息,请参阅https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet#Rule_- REMOVED -_Do_Not_Perform_Redirects_from_Non-TLS_Page_to_TLS_Login_Page.

我认为更好的解决方案是拒绝请求,并提供让用户知道原因的消息.您应该能够在中间件功能中执行此操作.您返回的实际状态代码值得商榷,但这样的事情应该有效:

app.use(function(req, res, next) {
    if(req.protocol !== 'https') {
        return res.status(403).send({message: 'SSL required'});
    }
    // allow the request to continue
    next();
});
Run Code Online (Sandbox Code Playgroud)