diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-12-09 09:43:55 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-12-09 09:43:55 +0000 |
| commit | 1837ccc618859e425766a66ff597b9f11b3e4e49 (patch) | |
| tree | 7dc17bd0205e53c180bb5ff912fe3a491c8a2acd /packages/backend/src/server/api/SigninApiService.ts | |
| parent | fix a bunch of CSS variables (diff) | |
| parent | merge: Implement new SkRateLimiterServer with Leaky Bucket rate limits (resol... (diff) | |
| download | sharkey-1837ccc618859e425766a66ff597b9f11b3e4e49.tar.gz sharkey-1837ccc618859e425766a66ff597b9f11b3e4e49.tar.bz2 sharkey-1837ccc618859e425766a66ff597b9f11b3e4e49.zip | |
Merge branch 'develop' into feature/2024.10
Diffstat (limited to 'packages/backend/src/server/api/SigninApiService.ts')
| -rw-r--r-- | packages/backend/src/server/api/SigninApiService.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts index 2945384e14..d1e58fb536 100644 --- a/packages/backend/src/server/api/SigninApiService.ts +++ b/packages/backend/src/server/api/SigninApiService.ts @@ -25,11 +25,13 @@ import { WebAuthnService } from '@/core/WebAuthnService.js'; import { UserAuthService } from '@/core/UserAuthService.js'; import { CaptchaService } from '@/core/CaptchaService.js'; import { FastifyReplyError } from '@/misc/fastify-reply-error.js'; -import { RateLimiterService } from './RateLimiterService.js'; +import { isSystemAccount } from '@/misc/is-system-account.js'; +import type { MiMeta } from '@/models/_.js'; +import { SkRateLimiterService } from '@/server/api/SkRateLimiterService.js'; +import { sendRateLimitHeaders } from '@/misc/rate-limit-utils.js'; import { SigninService } from './SigninService.js'; import type { AuthenticationResponseJSON } from '@simplewebauthn/types'; import type { FastifyReply, FastifyRequest } from 'fastify'; -import { isSystemAccount } from '@/misc/is-system-account.js'; @Injectable() export class SigninApiService { @@ -53,7 +55,7 @@ export class SigninApiService { private signinsRepository: SigninsRepository, private idService: IdService, - private rateLimiterService: RateLimiterService, + private rateLimiterService: SkRateLimiterService, private signinService: SigninService, private userAuthService: UserAuthService, private webAuthnService: WebAuthnService, @@ -92,10 +94,12 @@ export class SigninApiService { return { error }; } - try { // not more than 1 attempt per second and not more than 10 attempts per hour - await this.rateLimiterService.limit({ key: 'signin', duration: 60 * 60 * 1000, max: 10, minInterval: 1000 }, getIpHash(request.ip)); - } catch (err) { + const rateLimit = await this.rateLimiterService.limit({ key: 'signin', duration: 60 * 60 * 1000, max: 10, minInterval: 1000 }, getIpHash(request.ip)); + + sendRateLimitHeaders(reply, rateLimit); + + if (rateLimit.blocked) { reply.code(429); return { error: { |