diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-02-08 15:05:01 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-02-08 15:05:01 +0000 |
| commit | 50a3e55be4a86158f2dc393e3f98f803d8674120 (patch) | |
| tree | 1b3317609511cdf18b8b2a2c3e61fbc49c1e94f7 /packages/backend/src/server/api/SigninApiService.ts | |
| parent | merge: docker: add more packages (!890) (diff) | |
| parent | move imports to fix git diff in ActivityPubServerService.ts (diff) | |
| download | sharkey-50a3e55be4a86158f2dc393e3f98f803d8674120.tar.gz sharkey-50a3e55be4a86158f2dc393e3f98f803d8674120.tar.bz2 sharkey-50a3e55be4a86158f2dc393e3f98f803d8674120.zip | |
merge: Rework rate limit factors and add caching (resolves #884) (!884)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/884
Closes #884
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/server/api/SigninApiService.ts')
| -rw-r--r-- | packages/backend/src/server/api/SigninApiService.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts index fa9155d82d..72712bce60 100644 --- a/packages/backend/src/server/api/SigninApiService.ts +++ b/packages/backend/src/server/api/SigninApiService.ts @@ -26,12 +26,19 @@ import { UserAuthService } from '@/core/UserAuthService.js'; import { CaptchaService } from '@/core/CaptchaService.js'; import { FastifyReplyError } from '@/misc/fastify-reply-error.js'; import { isSystemAccount } from '@/misc/is-system-account.js'; -import { SkRateLimiterService } from '@/server/api/SkRateLimiterService.js'; -import { sendRateLimitHeaders } from '@/misc/rate-limit-utils.js'; +import { SkRateLimiterService } from '@/server/SkRateLimiterService.js'; +import { Keyed, RateLimit, sendRateLimitHeaders } from '@/misc/rate-limit-utils.js'; import { SigninService } from './SigninService.js'; import type { AuthenticationResponseJSON } from '@simplewebauthn/types'; import type { FastifyReply, FastifyRequest } from 'fastify'; +// Up to 10 attempts, then 1 per minute +const signinRateLimit: Keyed<RateLimit> = { + key: 'signin', + max: 10, + dripRate: 1000 * 60, +}; + @Injectable() export class SigninApiService { constructor( @@ -94,7 +101,7 @@ export class SigninApiService { } // not more than 1 attempt per second and not more than 10 attempts per hour - const rateLimit = await this.rateLimiterService.limit({ key: 'signin', duration: 60 * 60 * 1000, max: 10, minInterval: 1000 }, getIpHash(request.ip)); + const rateLimit = await this.rateLimiterService.limit(signinRateLimit, getIpHash(request.ip)); sendRateLimitHeaders(reply, rateLimit); |