From 8b970b35d7c899061c9a7d492abc2223321c394d Mon Sep 17 00:00:00 2001 From: Mohammad Ranjbar Z Date: Sun, 12 Sep 2021 19:46:07 +0430 Subject: [PATCH] Add whitelist ip for rate limit related to #610 --- config/default.json | 3 ++- src/utils/rateLimit.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index 7d7830fb..0b74c785 100644 --- a/config/default.json +++ b/config/default.json @@ -190,7 +190,8 @@ "createDonationTtlSeconds":3600, "createDonationThreshold":300, "createAuthenticationTtlSeconds":60, - "createAuthenticationThreshold":10 + "createAuthenticationThreshold":10, + "whitelist": [] }, "givethIoUrl": "https://serve.giveth.io/graphql", "givethIoProjectsReviewerAddress": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1" diff --git a/src/utils/rateLimit.js b/src/utils/rateLimit.js index dce95bd6..818cb76e 100644 --- a/src/utils/rateLimit.js +++ b/src/utils/rateLimit.js @@ -33,10 +33,15 @@ const rateLimit = (options = {}) => { context.params._populate || config.rateLimit.disable ) { - // Should not count internal requests + // Should not check rate limit return context; } const ip = context.params.headers['x-real-ip'] || context.params.headers.cookie; + if (config.rateLimit.whitelist && config.rateLimit.whitelist.includes(ip)) { + // Dont count rate limit for whitelist IPs + return context; + } + // if we just use ip as key, can not use separate rate limit for separate web services const key = `${context.path}-${context.method}-${ip}`; try {