根据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)
| 归档时间: |
|
| 查看次数: |
2758 次 |
| 最近记录: |