From ae31e90c30e28d0bafbda745cbb3abd37cfcac54 Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:43:17 +0100 Subject: [PATCH] feat(server): log rate limit exceeded --- server/core/middlewares/rate-limiter.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/core/middlewares/rate-limiter.ts b/server/core/middlewares/rate-limiter.ts index 3a707709e..4e1c5a33d 100644 --- a/server/core/middlewares/rate-limiter.ts +++ b/server/core/middlewares/rate-limiter.ts @@ -4,6 +4,7 @@ import { UserRole, UserRoleType } from '@peertube/peertube-models' import { CONFIG } from '@server/initializers/config.js' import { RunnerModel } from '@server/models/runner/runner.js' import { optionalAuthenticate } from './auth.js' +import { logger } from '@server/helpers/logger.js' const whitelistRoles = new Set([ UserRole.ADMINISTRATOR, UserRole.MODERATOR ]) @@ -24,7 +25,7 @@ export function buildRateLimiter (options: { .then(runner => { if (runner) return next() - return sendRateLimited(res, options) + return sendRateLimited(req, res, options) }) } @@ -34,7 +35,7 @@ export function buildRateLimiter (options: { return next() } - return sendRateLimited(res, options) + return sendRateLimited(req, res, options) }) } }) @@ -54,6 +55,8 @@ export const activityPubRateLimiter = buildRateLimiter({ // Private // --------------------------------------------------------------------------- -function sendRateLimited (res: express.Response, options: RateLimitHandlerOptions) { +function sendRateLimited (req: express.Request, res: express.Response, options: RateLimitHandlerOptions) { + logger.debug('Rate limit exceeded for route ' + req.originalUrl) + return res.status(options.statusCode).send(options.message) }