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

Add whitelist ip for rate limit #611

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
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
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