MCPcopy Create free account
hub / github.com/simstudioai/sim / enforceIpRateLimit

Function enforceIpRateLimit

apps/sim/lib/core/rate-limiter/route-helpers.ts:62–73  ·  view source on GitHub ↗
(
  bucketName: string,
  request: NextRequest,
  config: TokenBucketConfig = DEFAULT_PUBLIC_IP_ROUTE_LIMIT
)

Source from the content-addressed store, hash-verified

60 * `X-Forwarded-For: unknown` spoofing.
61 */
62export async function enforceIpRateLimit(
63 bucketName: string,
64 request: NextRequest,
65 config: TokenBucketConfig = DEFAULT_PUBLIC_IP_ROUTE_LIMIT
66): Promise<NextResponse | null> {
67 const ip = getClientIp(request)
68 const key = `route:${bucketName}:ip:${ip}`
69 const { allowed, resetAt } = await rateLimiter.checkRateLimitDirect(key, config)
70 if (allowed) return null
71 logger.warn('IP rate limit exceeded', { bucket: bucketName, ip })
72 return buildRateLimitResponse(resetAt)
73}
74
75/**
76 * Apply a per-user limit when a userId is present, else fall back to per-IP.

Callers 6

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
enforceUserOrIpRateLimitFunction · 0.85

Calls 4

getClientIpFunction · 0.90
buildRateLimitResponseFunction · 0.85
checkRateLimitDirectMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected