From c342726ad4ccbb90b8ff29f1cc1c89f9f7e8d98f Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 26 Apr 2019 13:48:55 +0200 Subject: Allow to control RATES_LIMIT from configuration (#1787) * Allow to control RATES_LIMIT from configuration * @Chocobozzz review (squash me) --- server/initializers/checker-before-init.ts | 3 ++- server/initializers/config.ts | 10 ++++++++++ server/initializers/constants.ts | 8 ++++---- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'server/initializers') diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 223ef8078..622ad7d6b 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts @@ -27,7 +27,8 @@ function checkMissedConfig () { 'services.twitter.username', 'services.twitter.whitelisted', 'followers.instance.enabled', 'followers.instance.manual_approval', 'tracker.enabled', 'tracker.private', 'tracker.reject_too_many_announces', - 'history.videos.max_age', 'views.videos.remote.max_age' + 'history.videos.max_age', 'views.videos.remote.max_age', + 'rates_limit.login.window', 'rates_limit.login.max', 'rates_limit.ask_send_email.window', 'rates_limit.ask_send_email.max' ] const requiredAlternatives = [ [ // set diff --git a/server/initializers/config.ts b/server/initializers/config.ts index baf502305..4f77e144d 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts @@ -63,6 +63,16 @@ const CONFIG = { HOSTNAME: config.get('webserver.hostname'), PORT: config.get('webserver.port') }, + RATES_LIMIT: { + LOGIN: { + WINDOW_MS: parseDurationToMs(config.get('rates_limit.login.window')), + MAX: config.get('rates_limit.login.max') + }, + ASK_SEND_EMAIL: { + WINDOW_MS: parseDurationToMs(config.get('rates_limit.ask_send_email.window')), + MAX: config.get('rates_limit.ask_send_email.max') + } + }, TRUST_PROXY: config.get('trust_proxy'), LOG: { LEVEL: config.get('log.level') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 2be364cc8..193bae5b5 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -281,12 +281,12 @@ let CONSTRAINTS_FIELDS = { const RATES_LIMIT = { LOGIN: { - WINDOW_MS: 5 * 60 * 1000, // 5 minutes - MAX: 15 // 15 attempts + WINDOW_MS: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS, + MAX: CONFIG.RATES_LIMIT.LOGIN.MAX }, ASK_SEND_EMAIL: { - WINDOW_MS: 5 * 60 * 1000, // 5 minutes - MAX: 3 // 3 attempts + WINDOW_MS: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS, + MAX: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.MAX } } -- cgit v1.2.3