Updated backend

- Added better anti DoS protection
- Added better security measures (HTTP headers, etc.)
- Added TLS support
- Added support for configurable rate limiting
- Added default 404 and error handling
- Updated proxy settings
- Updated env naming
This commit is contained in:
2024-03-31 20:50:58 +02:00
parent abd6f6747f
commit d93bfe333d
10 changed files with 147 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ import { log } from './logManager';
const requestLimiter = rateLimit({
windowMs: 60 * 1000,
max: 5,
max: process.env.RATE_LIMIT_REQUESTS || 100,
standardHeaders: true,
legacyHeaders: false,
message: 'Too many requests from this IP, please try again later',
@@ -18,6 +18,22 @@ const speedLimiter = slowDown({
delayMs: (hits) => hits * 100,
});
const antiBruteForce = rateLimit({
windowMs: 60 * 60 * 1000,
max: process.env.RATE_LIMIT_LOGIN_ATTEMPTS || 5,
standardHeaders: true,
legacyHeaders: false,
message: 'Too many login attempts, please try again later',
});
const antiVerificationSpam = rateLimit({
windowMs: 60 * 1000,
max: process.env.RATE_LIMIT_VERIFICATION_REQUESTS || 5,
standardHeaders: true,
legacyHeaders: false,
message: 'Too many verification requests, please try again later',
});
function checkSystemLoad(req, res, next) {
const load = os.loadavg()[0];
const cores = os.cpus().length;
@@ -49,6 +65,8 @@ function respondWithStatusJSON(res, statusCode, JSON) {
export {
requestLimiter,
antiBruteForce,
antiVerificationSpam,
speedLimiter,
checkSystemLoad,
respondWithStatus,