Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix(farcaster): throttle the public signer creation route

Gilad Resisi889f87f41778
diff --git a/apps/backend/src/api/routes/auth.controller.ts b/apps/backend/src/api/routes/auth.controller.ts
index db6b64739..0a4433216 100644
--- a/apps/backend/src/api/routes/auth.controller.ts
+++ b/apps/backend/src/api/routes/auth.controller.ts
@@ -7,7 +7,10 @@ import {
Query,
Req,
Res,
+ UseGuards,
} from '@nestjs/common';
+import { Throttle } from '@nestjs/throttler';
+import { ThrottlerRealIpGuard } from '@gitroom/nestjs-libraries/throttler/throttler.provider';
import { Response, Request } from 'express';
import { CreateOrgUserDto } from '@gitroom/nestjs-libraries/dtos/auth/create.org.user.dto';
@@ -286,6 +289,9 @@ export class AuthController {
}
}
+ // public and creates a signer at Neynar per call, so cap it per client
+ @UseGuards(ThrottlerRealIpGuard)
+ @Throttle({ default: { limit: 10, ttl: 3600000 } })
@Post('/farcaster/signer')
async farcasterSigner() {
try {
diff --git a/libraries/nestjs-libraries/src/throttler/throttler.provider.ts b/libraries/nestjs-libraries/src/throttler/throttler.provider.ts
index 72b218d55..db506f9ff 100644
--- a/libraries/nestjs-libraries/src/throttler/throttler.provider.ts
+++ b/libraries/nestjs-libraries/src/throttler/throttler.provider.ts
@@ -23,3 +23,15 @@ export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
);
}
}
+
+// route-level guard for public endpoints, keyed by the client address the
+// proxy forwards rather than the org the global guard expects
+@Injectable()
+export class ThrottlerRealIpGuard extends ThrottlerGuard {
+ protected override async getTracker(
+ req: Record<string, any>
+ ): Promise<string> {
+ const forwarded = String(req.headers?.['x-forwarded-for'] || '');
+ return forwarded.split(',')[0].trim() || req.ip;
+ }
+}