diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-12-16 19:56:44 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-12-16 19:56:44 +0900 |
| commit | d35ddc77d285879a4f5dd8a40497bf58930cb30e (patch) | |
| tree | 163b0a6f77c7481d33c29eb9c0e80dd5428193e8 /packages/backend/src/server/api/ApiCallService.ts | |
| parent | Update CHANGELOG.md (diff) | |
| download | misskey-d35ddc77d285879a4f5dd8a40497bf58930cb30e.tar.gz misskey-d35ddc77d285879a4f5dd8a40497bf58930cb30e.tar.bz2 misskey-d35ddc77d285879a4f5dd8a40497bf58930cb30e.zip | |
enhance(backend): request ip が localhost だった場合、レートリミットをスキップ & 警告を出すように
Diffstat (limited to 'packages/backend/src/server/api/ApiCallService.ts')
| -rw-r--r-- | packages/backend/src/server/api/ApiCallService.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts index 27c79ab438..261e147040 100644 --- a/packages/backend/src/server/api/ApiCallService.ts +++ b/packages/backend/src/server/api/ApiCallService.ts @@ -313,12 +313,16 @@ export class ApiCallService implements OnApplicationShutdown { } if (ep.meta.limit) { - // koa will automatically load the `X-Forwarded-For` header if `proxy: true` is configured in the app. - let limitActor: string; + let limitActor: string | null; if (user) { limitActor = user.id; } else { - limitActor = getIpHash(request.ip); + if (request.ip === '::1' || request.ip === '127.0.0.1') { + console.warn('request ip is localhost, maybe caused by misconfiguration of trustProxy or reverse proxy'); + limitActor = null; + } else { + limitActor = getIpHash(request.ip); + } } const limit = Object.assign({}, ep.meta.limit); @@ -330,7 +334,7 @@ export class ApiCallService implements OnApplicationShutdown { // TODO: 毎リクエスト計算するのもあれだしキャッシュしたい const factor = user ? (await this.roleService.getUserPolicies(user.id)).rateLimitFactor : 1; - if (factor > 0) { + if (limitActor != null && factor > 0) { // Rate limit const rateLimit = await this.rateLimiterService.limit(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor, factor); if (rateLimit != null) { |