Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #611 from Giveth/f_610_add_whitelist_for_ratelimit
Browse files Browse the repository at this point in the history
Add whitelist ip for rate limit
  • Loading branch information
aminlatifi authored Sep 13, 2021
2 parents 7b08ef6 + 8b970b3 commit 1c3301f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
"createDonationTtlSeconds":3600,
"createDonationThreshold":300,
"createAuthenticationTtlSeconds":60,
"createAuthenticationThreshold":10
"createAuthenticationThreshold":10,
"whitelist": []
},
"givethIoUrl": "https://serve.giveth.io/graphql",
"givethIoProjectsReviewerAddress": "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"
Expand Down
7 changes: 6 additions & 1 deletion src/utils/rateLimit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1c3301f

Please sign in to comment.