Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add ability to disable rate limits

Chocobozzz94c11329b4b2
diff --git a/config/config-schema.json b/config/config-schema.json
index 7dce7659e3..4db2657f59 100644
--- a/config/config-schema.json
+++ b/config/config-schema.json
@@ -67,6 +67,10 @@
"api": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "50 attempts in 10 seconds",
"type": "string",
@@ -82,6 +86,10 @@
"login": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "15 attempts in 5 min",
"type": "string",
@@ -97,6 +105,10 @@
"signup": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "2 attempts in 5 min (only succeeded attempts are taken into account)",
"type": "string",
@@ -112,6 +124,10 @@
"ask_send_email": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "3 attempts in 5 min",
"type": "string",
@@ -127,6 +143,10 @@
"confirm_token": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "Consuming a token sent by email/OTP (reset password, verify email, confirm 2FA) 10 attempts in 5 min",
"type": "string",
@@ -142,6 +162,10 @@
"receive_client_log": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "1 attempt every 2 seconds",
"type": "string",
@@ -157,6 +181,10 @@
"plugins": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "500 attempts in 10 seconds (we also serve plugin static files)",
"type": "string",
@@ -172,6 +200,10 @@
"well_known": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "200 attempts in 10 seconds",
"type": "string",
@@ -187,6 +219,10 @@
"feeds": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "50 attempts in 10 seconds",
"type": "string",
@@ -202,6 +238,10 @@
"activity_pub": {
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "500 attempts in 10 seconds (we can have many AP requests)",
"type": "string",
@@ -218,6 +258,10 @@
"description": "HTML files generated by PeerTube",
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "500 attempts in 10 seconds (to not break crawlers)",
"type": "string",
@@ -234,6 +278,10 @@
"description": "A light FFmpeg process is used to generate videos (to merge audio and video streams for example)",
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "5 attempts in 5 seconds",
"type": "string",
@@ -250,6 +298,10 @@
"description": "Abuse reports, limited per authenticated user (each report notifies all moderators)",
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "20 attempts in 1 hour",
"type": "string",
@@ -266,6 +318,10 @@
"description": "Comment/reply creation, limited per authenticated user",
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": true
+ },
"window": {
"description": "60 attempts in 5 minutes",
"type": "string",
@@ -282,6 +338,10 @@
"description": "Lock an account after too many password/OTP login failures",
"type": "object",
"properties": {
+ "enabled": {
+ "type": "boolean",
+ "default": false
+ },
"window": {
"type": "string",
"default": "5 minutes"
diff --git a/config/default.yaml b/config/default.yaml
index 1cd38e70bc..e71ee05e2e 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -23,63 +23,78 @@ http_timeouts:
# Limit number of HTTP requests per IP
rates_limit:
api:
+ enabled: true
# 50 attempts in 10 seconds
window: 10 seconds
max: 50
login:
+ enabled: true
# 15 attempts in 5 min
window: 5 minutes
max: 15
signup:
+ enabled: true
# 2 attempts in 5 min (only succeeded attempts are taken into account)
window: 5 minutes
max: 2
ask_send_email:
+ enabled: true
# 3 attempts in 5 min
window: 5 minutes
max: 3
confirm_token:
+ enabled: true
# Consuming a token sent by email/OTP (reset password, verify email, confirm 2FA)
# 10 attempts in 5 min
window: 5 minutes
max: 10
receive_client_log:
+ enabled: true
# 1 attempt every 2 seconds
window: 1 minute
max: 30
plugins:
+ enabled: true
# 500 attempts in 10 seconds (we also serve plugin static files)
window: 10 seconds
max: 500
well_known:
+ enabled: true
# 200 attempts in 10 seconds
window: 10 seconds
max: 200
feeds:
+ enabled: true
# 50 attempts in 10 seconds
window: 10 seconds
max: 50
activity_pub:
+ enabled: true
# 500 attempts in 10 seconds (we can have many AP requests)
window: 10 seconds
max: 500
client: # HTML files generated by PeerTube
+ enabled: true
# 500 attempts in 10 seconds (to not break crawlers)
window: 10 seconds
max: 500
download_generate_video: # A light FFmpeg process is used to generate videos (to merge audio and video streams for example)
+ enabled: true
# 5 attempts in 5 seconds
window: 5 seconds
max: 5
report_abuse: # Abuse reports, limited per authenticated user (each report notifies all moderators)
+ enabled: true
# 20 attempts in 1 hour
window: 1 hour
max: 20
create_comment: # Comment/reply creation, limited per authenticated user
+ enabled: true
# 60 attempts in 5 minutes
window: 5 minutes
max: 60
login_lockout: # Lock an account after too many password/OTP login failures
+ enabled: false
window: 5 minutes
max: 60 # Requires at least 10 distinct IPs (`max / max_per_ip`) to lock an account
max_per_ip: 6 # A single IP's contribution to the account lock is capped at 6 failures
diff --git a/config/production.yaml.example b/config/production.yaml.example
index 1bb389a8d9..bdfffe826c 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -21,63 +21,78 @@ http_timeouts:
# Limit number of HTTP requests per IP
rates_limit:
api:
+ enabled: true
# 50 attempts in 10 seconds
window: 10 seconds
max: 50
login:
+ enabled: true
# 15 attempts in 5 min
window: 5 minutes
max: 15
signup:
+ enabled: true
# 2 attempts in 5 min (only succeeded attempts are taken into account)
window: 5 minutes
max: 2
ask_send_email:
+ enabled: true
# 3 attempts in 5 min
window: 5 minutes
max: 3
confirm_token:
+ enabled: true
# Consuming a token sent by email/OTP (reset password, verify email, confirm 2FA)
# 10 attempts in 5 min
window: 5 minutes
max: 10
receive_client_log:
+ enabled: true
# 1 attempt every 2 seconds
window: 1 minute
max: 30
plugins:
+ enabled: true
# 500 attempts in 10 seconds (we also serve plugin static files)
window: 10 seconds
max: 500
well_known:
+ enabled: true
# 200 attempts in 10 seconds
window: 10 seconds
max: 200
feeds:
+ enabled: true
# 50 attempts in 10 seconds
window: 10 seconds
max: 50
activity_pub:
+ enabled: true
# 500 attempts in 10 seconds (we can have many AP requests)
window: 10 seconds
max: 500
client: # HTML files generated by PeerTube
+ enabled: true
# 500 attempts in 10 seconds (to not break crawlers)
window: 10 seconds
max: 500
download_generate_video: # A light FFmpeg process is used to generate videos (to merge audio and video streams for example)
+ enabled: true
# 5 attempts in 5 seconds
window: 5 seconds
max: 5
report_abuse: # Abuse reports, limited per authenticated user (each report notifies all moderators)
+ enabled: true
# 20 attempts in 1 hour
window: 1 hour
max: 20
create_comment: # Comment/reply creation, limited per authenticated user
+ enabled: true
# 60 attempts in 5 minutes
window: 5 minutes
max: 60
login_lockout: # Lock an account after too many password/OTP login failures
+ enabled: false
window: 5 minutes
max: 60 # Requires at least 10 distinct IPs (`max / max_per_ip`) to lock an account
max_per_ip: 6 # A single IP's contribution to the account lock is capped at 6 failures
diff --git a/config/test.yaml b/config/test.yaml
index 4afd76659f..3e3453e7fb 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -29,6 +29,7 @@ rates_limit:
window: 10 seconds
max: 500
login_lockout:
+ enabled: true
window: 5 seconds
max: 10
max_per_ip: 3
diff --git a/packages/tests/src/api/users/login-lockout.ts b/packages/tests/src/api/users/login-lockout.ts
index ebbb712901..06b5598379 100644
--- a/packages/tests/src/api/users/login-lockout.ts
+++ b/packages/tests/src/api/users/login-lockout.ts
@@ -24,6 +24,7 @@ describe('Test login lockout', function () {
let userToken: string
const emails: object[] = []
+ let emailPort: number
// Sync with rates_limit.login_lockout in config/test.yaml (window is 5 seconds on a test instance)
const maxFailures = 10
@@ -86,7 +87,7 @@ describe('Test login lockout', function () {
before(async function () {
this.timeout(30000)
- const port = await MockSmtpServer.Instance.collectEmails(emails)
+ emailPort = await MockSmtpServer.Instance.collectEmails(emails)
// Increase the IP based login rate limit so this test only triggers the per-account lockout
server = await createSingleServer(1, {
@@ -96,7 +97,7 @@ describe('Test login lockout', function () {
max: 1000
}
},
- ...ConfigCommand.getEmailOverrideConfig(port)
+ ...ConfigCommand.getEmailOverrideConfig(emailPort)
})
await setAccessTokensToServers([ server ])
@@ -232,6 +233,75 @@ describe('Test login lockout', function () {
expectLockedAccountEmailsCount(2)
})
+ // Login lockout is disabled by default
+ describe('When login lockout is disabled', function () {
+ it('Should never lock an account however many failures it gets', async function () {
+ this.timeout(30000)
+
+ await server.kill()
+ await server.run({
+ rates_limit: {
+ login: { window: '5 minutes', max: 1000 },
+ login_lockout: { enabled: false }
+ },
+ ...ConfigCommand.getEmailOverrideConfig(emailPort)
+ })
+
+ const { password: otherUserPassword } = await server.users.generate('user2')
+
+ const emailsCountBefore = emails.length
+
+ for (let i = 0; i < maxFailures * 2; i++) {
+ await server.login.loginAndGetResponse({
+ user: { username: 'user2', password: 'invalid password' },
+ xForwardedFor: xForwardedForAt(i),
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+ }
+
+ await server.login.login({
+ user: { username: 'user2', password: otherUserPassword },
+ expectedStatus: HttpStatusCode.OK_200
+ })
+
+ await waitJobs(server)
+
+ expect(emails).to.have.lengthOf(emailsCountBefore)
+ })
+ })
+
+ describe('When root auth is disabled', function () {
+ it('Should not send a login lockout notification for repeated failed root logins', async function () {
+ this.timeout(30000)
+
+ await server.kill()
+ await server.run({
+ user: { disable_root_auth: true },
+ rates_limit: {
+ login: { window: '5 minutes', max: 1000 }
+ },
+ ...ConfigCommand.getEmailOverrideConfig(emailPort)
+ })
+
+ const emailsCountBefore = emails.length
+
+ for (let i = 0; i < maxFailures * 2; i++) {
+ const { body } = await server.login.loginAndGetResponse({
+ user: { username: 'root', password: 'whatever password' },
+ xForwardedFor: xForwardedForAt(i),
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
+ })
+
+ expectGenericInvalidGrant(body)
+ }
+
+ // Can't use waitJobs because root tokens were invalidated
+ await wait(2000)
+
+ expect(emails).to.have.lengthOf(emailsCountBefore)
+ })
+ })
+
after(async function () {
await MockSmtpServer.Instance.kill()
diff --git a/server/core/controllers/api/abuse.ts b/server/core/controllers/api/abuse.ts
index b2f483b320..a8aa5a615a 100644
--- a/server/core/controllers/api/abuse.ts
+++ b/server/core/controllers/api/abuse.ts
@@ -42,6 +42,7 @@ abuseRouter.use(apiRateLimiter)
// Each accepted report notifies every moderator (in-app + email) and can federate a Flag activity
// So also limit reports per user
const reportAbuseRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.REPORT_ABUSE.ENABLED,
windowMs: CONFIG.RATES_LIMIT.REPORT_ABUSE.WINDOW_MS,
max: CONFIG.RATES_LIMIT.REPORT_ABUSE.MAX,
perUserKey: true
diff --git a/server/core/controllers/api/server/logs.ts b/server/core/controllers/api/server/logs.ts
index 33da50575b..9b782061e6 100644
--- a/server/core/controllers/api/server/logs.ts
+++ b/server/core/controllers/api/server/logs.ts
@@ -13,6 +13,7 @@ import { createClientLogValidator, getAuditLogsValidator, getLogsValidator } fro
const logger = createLogger()
const createClientLogRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.RECEIVE_CLIENT_LOG.ENABLED,
windowMs: CONFIG.RATES_LIMIT.RECEIVE_CLIENT_LOG.WINDOW_MS,
max: CONFIG.RATES_LIMIT.RECEIVE_CLIENT_LOG.MAX
})
diff --git a/server/core/controllers/api/users/email-verification.ts b/server/core/controllers/api/users/email-verification.ts
index 84e5b76f2d..2702dee636 100644
--- a/server/core/controllers/api/users/email-verification.ts
+++ b/server/core/controllers/api/users/email-verification.ts
@@ -12,6 +12,7 @@ import {
} from '../../../middlewares/validators/index.js'
const askSendEmailLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.ENABLED,
windowMs: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS,
max: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.MAX
})
diff --git a/server/core/controllers/api/users/index.ts b/server/core/controllers/api/users/index.ts
index eac28dc50b..a67236a528 100644
--- a/server/core/controllers/api/users/index.ts
+++ b/server/core/controllers/api/users/index.ts
@@ -58,6 +58,7 @@ const logger = createLogger('api', 'users')
const auditLogger = auditLoggerFactory('users')
const askResetPasswordRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.ENABLED,
windowMs: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.WINDOW_MS,
max: CONFIG.RATES_LIMIT.ASK_SEND_EMAIL.MAX
})
diff --git a/server/core/controllers/api/users/registrations.ts b/server/core/controllers/api/users/registrations.ts
index 630f1b5240..b2002b35d5 100644
--- a/server/core/controllers/api/users/registrations.ts
+++ b/server/core/controllers/api/users/registrations.ts
@@ -47,6 +47,7 @@ const logger = createLogger()
const auditLogger = auditLoggerFactory('users')
const registrationRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.SIGNUP.ENABLED,
windowMs: CONFIG.RATES_LIMIT.SIGNUP.WINDOW_MS,
max: CONFIG.RATES_LIMIT.SIGNUP.MAX,
skipFailedRequests: true
diff --git a/server/core/controllers/api/users/token.ts b/server/core/controllers/api/users/token.ts
index 0f79a3080e..373fcce58c 100644
--- a/server/core/controllers/api/users/token.ts
+++ b/server/core/controllers/api/users/token.ts
@@ -30,6 +30,7 @@ const logger = createLogger()
const tokensRouter = express.Router()
const loginRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.LOGIN.ENABLED,
windowMs: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS,
max: CONFIG.RATES_LIMIT.LOGIN.MAX
})
diff --git a/server/core/controllers/api/videos/comment.ts b/server/core/controllers/api/videos/comment.ts
index a4bd483d77..ae0e916148 100644
--- a/server/core/controllers/api/videos/comment.ts
+++ b/server/core/controllers/api/videos/comment.ts
@@ -49,6 +49,7 @@ const videoCommentRouter = express.Router()
// Each comment fans out notifications and ActivityPub deliveries to followers
// So also limit comment creation per user
const createCommentRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.CREATE_COMMENT.ENABLED,
windowMs: CONFIG.RATES_LIMIT.CREATE_COMMENT.WINDOW_MS,
max: CONFIG.RATES_LIMIT.CREATE_COMMENT.MAX,
perUserKey: true
diff --git a/server/core/controllers/client.ts b/server/core/controllers/client.ts
index a7f83f20fd..fce3a99ad4 100644
--- a/server/core/controllers/client.ts
+++ b/server/core/controllers/client.ts
@@ -18,6 +18,7 @@ const logger = createLogger()
const clientsRouter = express.Router()
const clientsRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.CLIENT.ENABLED,
windowMs: CONFIG.RATES_LIMIT.CLIENT.WINDOW_MS,
max: CONFIG.RATES_LIMIT.CLIENT.MAX
})
diff --git a/server/core/controllers/download.ts b/server/core/controllers/download.ts
index 2a826ba174..5acce66aeb 100644
--- a/server/core/controllers/download.ts
+++ b/server/core/controllers/download.ts
@@ -67,6 +67,7 @@ downloadRouter.use(
)
const downloadGenerateRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.DOWNLOAD_GENERATE_VIDEO.ENABLED,
windowMs: CONFIG.RATES_LIMIT.DOWNLOAD_GENERATE_VIDEO.WINDOW_MS,
max: CONFIG.RATES_LIMIT.DOWNLOAD_GENERATE_VIDEO.MAX,
skipFailedRequests: true
diff --git a/server/core/controllers/feeds/index.ts b/server/core/controllers/feeds/index.ts
index b7210372f7..3058937456 100644
--- a/server/core/controllers/feeds/index.ts
+++ b/server/core/controllers/feeds/index.ts
@@ -8,6 +8,7 @@ import { videoPodcastFeedsRouter } from './video-podcast-feeds.js'
const feedsRouter = express.Router()
const feedsRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.FEEDS.ENABLED,
windowMs: CONFIG.RATES_LIMIT.FEEDS.WINDOW_MS,
max: CONFIG.RATES_LIMIT.FEEDS.MAX
})
diff --git a/server/core/controllers/plugins.ts b/server/core/controllers/plugins.ts
index aef58ca417..163e99763b 100644
--- a/server/core/controllers/plugins.ts
+++ b/server/core/controllers/plugins.ts
@@ -22,6 +22,7 @@ const sendFileOptions = {
const pluginsRouter = express.Router()
const pluginsRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.PLUGINS.ENABLED,
windowMs: CONFIG.RATES_LIMIT.PLUGINS.WINDOW_MS,
max: CONFIG.RATES_LIMIT.PLUGINS.MAX
})
diff --git a/server/core/controllers/well-known.ts b/server/core/controllers/well-known.ts
index a9d077228c..dbf5b04cfc 100644
--- a/server/core/controllers/well-known.ts
+++ b/server/core/controllers/well-known.ts
@@ -10,6 +10,7 @@ import { cacheRoute } from '../middlewares/cache/cache.js'
const wellKnownRouter = express.Router()
const wellKnownRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.WELL_KNOWN.ENABLED,
windowMs: CONFIG.RATES_LIMIT.WELL_KNOWN.WINDOW_MS,
max: CONFIG.RATES_LIMIT.WELL_KNOWN.MAX
})
diff --git a/server/core/initializers/config.ts b/server/core/initializers/config.ts
index 8498b25772..6951417ad7 100644
--- a/server/core/initializers/config.ts
+++ b/server/core/initializers/config.ts
@@ -449,62 +449,77 @@ const CONFIG = {
},
RATES_LIMIT: {
API: {
+ ENABLED: config.get<boolean>('rates_limit.api.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.api.window')),
MAX: config.get<number>('rates_limit.api.max')
},
SIGNUP: {
+ ENABLED: config.get<boolean>('rates_limit.signup.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.signup.window')),
MAX: config.get<number>('rates_limit.signup.max')
},
LOGIN: {
+ ENABLED: config.get<boolean>('rates_limit.login.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.login.window')),
MAX: config.get<number>('rates_limit.login.max')
},
RECEIVE_CLIENT_LOG: {
+ ENABLED: config.get<boolean>('rates_limit.receive_client_log.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.receive_client_log.window')),
MAX: config.get<number>('rates_limit.receive_client_log.max')
},
ASK_SEND_EMAIL: {
+ ENABLED: config.get<boolean>('rates_limit.ask_send_email.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.ask_send_email.window')),
MAX: config.get<number>('rates_limit.ask_send_email.max')
},
CONFIRM_TOKEN: {
+ ENABLED: config.get<boolean>('rates_limit.confirm_token.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.confirm_token.window')),
MAX: config.get<number>('rates_limit.confirm_token.max')
},
PLUGINS: {
+ ENABLED: config.get<boolean>('rates_limit.plugins.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.plugins.window')),
MAX: config.get<number>('rates_limit.plugins.max')
},
WELL_KNOWN: {
+ ENABLED: config.get<boolean>('rates_limit.well_known.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.well_known.window')),
MAX: config.get<number>('rates_limit.well_known.max')
},
FEEDS: {
+ ENABLED: config.get<boolean>('rates_limit.feeds.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.feeds.window')),
MAX: config.get<number>('rates_limit.feeds.max')
},
ACTIVITY_PUB: {
+ ENABLED: config.get<boolean>('rates_limit.activity_pub.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.activity_pub.window')),
MAX: config.get<number>('rates_limit.activity_pub.max')
},
CLIENT: {
+ ENABLED: config.get<boolean>('rates_limit.client.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.client.window')),
MAX: config.get<number>('rates_limit.client.max')
},
DOWNLOAD_GENERATE_VIDEO: {
+ ENABLED: config.get<boolean>('rates_limit.download_generate_video.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.download_generate_video.window')),
MAX: config.get<number>('rates_limit.download_generate_video.max')
},
REPORT_ABUSE: {
+ ENABLED: config.get<boolean>('rates_limit.report_abuse.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.report_abuse.window')),
MAX: config.get<number>('rates_limit.report_abuse.max')
},
CREATE_COMMENT: {
+ ENABLED: config.get<boolean>('rates_limit.create_comment.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.create_comment.window')),
MAX: config.get<number>('rates_limit.create_comment.max')
},
LOGIN_LOCKOUT: {
+ ENABLED: config.get<boolean>('rates_limit.login_lockout.enabled'),
WINDOW_MS: parseDurationToMs(config.get<string>('rates_limit.login_lockout.window')),
MAX: config.get<number>('rates_limit.login_lockout.max'),
MAX_PER_IP: config.get<number>('rates_limit.login_lockout.max_per_ip')
diff --git a/server/core/lib/auth/oauth-user.ts b/server/core/lib/auth/oauth-user.ts
index 127cfa210e..1c62a84d33 100644
--- a/server/core/lib/auth/oauth-user.ts
+++ b/server/core/lib/auth/oauth-user.ts
@@ -83,14 +83,16 @@ export async function getUserOrThrow (options: {
// Check the per-account login failures counter so a locked account cannot have its password/OTP brute-forced
// Throw the exact same generic error as invalid credentials: a distinct error/status here would let an
// attacker use the lockout itself as a username-enumeration oracle (try N failed logins, see if it flips)
- if (await Redis.Instance.getLoginFailures(user.id) >= CONFIG.RATES_LIMIT.LOGIN_LOCKOUT.MAX) {
+ if (CONFIG.RATES_LIMIT.LOGIN_LOCKOUT.ENABLED && await Redis.Instance.getLoginFailures(user.id) >= CONFIG.RATES_LIMIT.LOGIN_LOCKOUT.MAX) {
throwInvalidGrantError()
}
const passwordMatch = await user.isPasswordMatch(password)
if (passwordMatch !== true) {
- const failures = await Redis.Instance.addLoginFailure(user.id, req.ip)
- await notifyAccountLockedIfNeeded(user, failures, req.ip)
+ if (CONFIG.RATES_LIMIT.LOGIN_LOCKOUT.ENABLED) {
+ const failures = await Redis.Instance.addLoginFailure(user.id, req.ip)
+ await notifyAccountLockedIfNeeded(user, failures, req.ip)
+ }
throwInvalidGrantError()
}
@@ -108,8 +110,10 @@ export async function getUserOrThrow (options: {
}
if (await isOTPValid({ encryptedSecret: user.otpSecret, token: oauthHeaders[OTP.HEADER_NAME] }) !== true) {
- const failures = await Redis.Instance.addLoginFailure(user.id, req.ip)
- await notifyAccountLockedIfNeeded(user, failures, req.ip)
+ if (CONFIG.RATES_LIMIT.LOGIN_LOCKOUT.ENABLED) {
+ const failures = await Redis.Instance.addLoginFailure(user.id, req.ip)
+ await notifyAccountLockedIfNeeded(user, failures, req.ip)
+ }
throw new InvalidTwoFactorError(req.t('Invalid two factor header'))
}
diff --git a/server/core/middlewares/rate-limiter.ts b/server/core/middlewares/rate-limiter.ts
index 6838719c29..25f3d0a926 100644
--- a/server/core/middlewares/rate-limiter.ts
+++ b/server/core/middlewares/rate-limiter.ts
@@ -12,6 +12,7 @@ const logger = createLogger('rate-limit')
const whitelistRoles = new Set<UserRoleType>([ UserRole.ADMINISTRATOR, UserRole.MODERATOR ])
export function buildRateLimiter (options: {
+ enabled?: boolean // Default: true
windowMs: number
max: number
skipFailedRequests?: boolean
@@ -19,9 +20,13 @@ export function buildRateLimiter (options: {
// Key the counter on the authenticated user instead of the source IP
perUserKey?: boolean
}) {
+ if (options.enabled === false) {
+ return (req: express.Request, res: express.Response, next: express.NextFunction) => next()
+ }
+
return RateLimit({
windowMs: options.windowMs,
- max: options.max,
+ limit: options.max,
skipFailedRequests: options.skipFailedRequests,
keyGenerator: options.perUserKey === true
@@ -58,17 +63,20 @@ export function buildRateLimiter (options: {
}
export const apiRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.API.ENABLED,
windowMs: CONFIG.RATES_LIMIT.API.WINDOW_MS,
max: CONFIG.RATES_LIMIT.API.MAX
})
// Endpoints that consume a token sent by email or generated for the user (reset password, verify email, confirm 2FA)
export const confirmTokenRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.CONFIRM_TOKEN.ENABLED,
windowMs: CONFIG.RATES_LIMIT.CONFIRM_TOKEN.WINDOW_MS,
max: CONFIG.RATES_LIMIT.CONFIRM_TOKEN.MAX
})
export const activityPubRateLimiter = buildRateLimiter({
+ enabled: CONFIG.RATES_LIMIT.ACTIVITY_PUB.ENABLED,
windowMs: CONFIG.RATES_LIMIT.ACTIVITY_PUB.WINDOW_MS,
max: CONFIG.RATES_LIMIT.ACTIVITY_PUB.MAX
})