summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/ApiCallService.ts
diff options
context:
space:
mode:
authorJulia <julia@insertdomain.name>2024-11-28 05:23:38 +0000
committerJulia <julia@insertdomain.name>2024-11-28 05:23:38 +0000
commit150d949a3ec2b5162e2dfda10c2cc5dddea8c59a (patch)
treea1854b0cfcc91e8148f2df722237df08b6520537 /packages/backend/src/server/api/ApiCallService.ts
parentmerge: Fix `.punyHost` misuse (!765) (diff)
parentmerge: Add shared (cross-resource) rate limit for proxy (!775) (diff)
downloadsharkey-150d949a3ec2b5162e2dfda10c2cc5dddea8c59a.tar.gz
sharkey-150d949a3ec2b5162e2dfda10c2cc5dddea8c59a.tar.bz2
sharkey-150d949a3ec2b5162e2dfda10c2cc5dddea8c59a.zip
merge: fixes for 2024.9.4 (if we want to) (!770)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/770 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Julia <julia@insertdomain.name>
Diffstat (limited to 'packages/backend/src/server/api/ApiCallService.ts')
-rw-r--r--packages/backend/src/server/api/ApiCallService.ts12
1 files changed, 10 insertions, 2 deletions
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts
index 016db6ac19..6f51825494 100644
--- a/packages/backend/src/server/api/ApiCallService.ts
+++ b/packages/backend/src/server/api/ApiCallService.ts
@@ -311,7 +311,15 @@ export class ApiCallService implements OnApplicationShutdown {
throw new ApiError(accessDenied);
}
- if (ep.meta.limit) {
+ // For endpoints without a limit, the default is 10 calls per second
+ const endpointLimit: IEndpointMeta['limit'] = ep.meta.limit ?? {
+ duration: 1000,
+ max: 10,
+ };
+
+ // We don't need this check, but removing it would cause a big merge conflict.
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+ if (endpointLimit) {
// koa will automatically load the `X-Forwarded-For` header if `proxy: true` is configured in the app.
let limitActor: string;
if (user) {
@@ -320,7 +328,7 @@ export class ApiCallService implements OnApplicationShutdown {
limitActor = getIpHash(request.ip);
}
- const limit = Object.assign({}, ep.meta.limit);
+ const limit = Object.assign({}, endpointLimit);
if (limit.key == null) {
(limit as any).key = ep.name;