mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	merge: Add default rate limit (!768)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/768 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Tess K <me@thvxl.se> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
		
						commit
						caaa78d98d
					
				
					 1 changed files with 10 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue