Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/middlewares/rateLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ async function checkRequest(ip: string, request: RpcRequest): Promise<boolean> {
return await requestersList.isRequestOkay(ip, request.method, request.params)
}

function isInternalRequest(ip: string): boolean {
// Check for localhost and internal IP patterns
return (
ip === 'localhost' ||
ip === '127.0.0.1' ||
ip.startsWith('127.') ||
ip === '0.0.0.0' ||
ip === '::1'
)
}

export async function rateLimitMiddleware(req: Request, res: Response, next: NextFunction) {
if (!config.rateLimit) {
next()
Expand All @@ -38,6 +49,12 @@ export async function rateLimitMiddleware(req: Request, res: Response, next: Nex
ip = ip.substring(7)
}

// Skip rate limiting for internal requests
if (isInternalRequest(ip)) {
next()
return
}

const requests: RpcRequest[] = Array.isArray(req.body) ? req.body : [req.body]

try {
Expand Down
Loading