Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

refactor(agent-signup): reorder imports and improve IP rate limiting logic

Erik Engervall10f739b4bc3c
diff --git a/apps/api/src/controllers/v2/agent-signup.ts b/apps/api/src/controllers/v2/agent-signup.ts
index b5ecfcb06..8916aeef0 100644
--- a/apps/api/src/controllers/v2/agent-signup.ts
+++ b/apps/api/src/controllers/v2/agent-signup.ts
@@ -1,13 +1,13 @@
-import { Request, Response } from "express";
-import { z } from "zod";
import crypto from "crypto";
-import { supabase_service, supabase_rr_service } from "../../services/supabase";
-import { apiKeyToFcApiKey } from "../../lib/parseApi";
-import { logger as _logger } from "../../lib/logger";
+import { Request, Response } from "express";
+import { RateLimiterRedis } from "rate-limiter-flexible";
import { Resend } from "resend";
+import { z } from "zod";
import { config } from "../../config";
-import { RateLimiterRedis } from "rate-limiter-flexible";
+import { logger as _logger } from "../../lib/logger";
+import { apiKeyToFcApiKey } from "../../lib/parseApi";
import { redisRateLimitClient } from "../../services/rate-limiter";
+import { supabase_rr_service, supabase_service } from "../../services/supabase";
const PUBLIC_EMAIL_DOMAINS = new Set([
"gmail.com",
@@ -64,10 +64,9 @@ export async function agentSignupController(req: Request, res: Response) {
const body = agentSignupSchema.parse(req.body);
const { email, agent_name } = body;
- // Rate limit by IP
- const incomingIP = (req.headers["x-forwarded-for"] ||
- req.socket.remoteAddress ||
- "unknown") as string;
+ // Rate limit by IP (use req.ip so we respect Express trust proxy and don't
+ // trust client-controlled X-Forwarded-For; req.ip parses the forwarded chain correctly)
+ const incomingIP = req.ip || req.socket.remoteAddress || "unknown";
try {
await ipRateLimiter.consume(incomingIP);
} catch {