Currently, if we set httpNodeAuth
in settings.js, a middleware function using basic-auth is applied at the top-level of the httpNode express app. It protects all routes beneath it including those of the http in node, dashboard, and any routes added by other nodes to httpNode. And depending on how you define httpNodeRoot
and httpStaticRoot
, it may also protect static routes.
httpNodeAuth: { user:"user", pass:"$2b$14$B.jppbe..."},
If the httpNodeAuth
property can also except a middleware function or array of middleware functions, then we can inject our own custom authentication system at the same location where the basic-auth middleware would have been added at the top-level:
httpNodeAuth: [
httpBlocker, // blocks ip(s) that were dynamically banned
httpRouter, // express router handles login/logout routes
httpSession, // attaches session to all routes not matched in httpRouter
httpVerify, // verifies session has authorization to access resource
],
I have implemented this on my system for the last couple months and it is working well with the following points:
- backwards compatible / non breaking change
- does not affect httpAdmin authentication
- browsers offers to save and populate the user/pass in the login form
- advanced features such as tracking and terminating socket. io connections
- only allowing user to be logged in from 1 device at a time by managing sessions
- dynamically blocking ip addresses for multiple failed login attempts
- function node receives event for failed login attempts and then can send alert msg to admin
And I must point out that is not equivalent to using httpNodeMiddleware
, since that only adds middleware functions to the individual http in node routes and not at the top level. The name of that property implies middleware is added to the httpNode, but unfortunately it does not. It probably should be called httpInMiddleware
, but maybe it's too late to change that without creating deprecation warnings and all that noise.
Also, being able to create a custom auth system is not a substitute for using other software such as iptables and reverse proxies, but it should work in conjunction with them. For example, if an ip gets blocked due to multiple failed login attempts, the function node listening to the events can send a msg to a file node and write the ip to the blocked list while also sending an alert email to the system admin. Perhaps some cron process can occasionally read from that file and update iptables with the current list of naughty ip addresses, etc.
It would only be a few lines of code to change and I would be more than happy to submit the pr.