From fa1f87c5c8f1f6769085f5155052eb95ba77c262 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Wed, 10 Mar 2021 10:09:18 -0800 Subject: [PATCH] fix(rate limits): Bumping resolution to 10,000 points per minute --- config/index.js | 4 ++-- src/middleware/route-ratelimit.js | 13 +++++++------ test/v4/rate-limit-unit.js | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config/index.js b/config/index.js index 874a465..34fb58f 100644 --- a/config/index.js +++ b/config/index.js @@ -12,13 +12,13 @@ const config = { // Rate Limits anonRateLimit: process.env.ANON_RATE_LIMIT ? Number(process.env.ANON_RATE_LIMIT) - : 50, + : 500, whitelistRateLimit: process.env.WHITELIST_RATE_LIMIT ? Number(process.env.WHITELIST_RATE_LIMIT) : 10, pointsPerMinute: process.env.POINTS_PER_MINUTE ? Number(process.env.POINTS_PER_MINUTE) - : 1000, + : 10000, whitelistDomains: process.env.WHITELIST_DOMAINS ? process.env.WHITELIST_DOMAINS.split(',') : ['fullstack.cash', 'psfoundation.cash', '10.0.'] diff --git a/src/middleware/route-ratelimit.js b/src/middleware/route-ratelimit.js index 0745523..a315184 100644 --- a/src/middleware/route-ratelimit.js +++ b/src/middleware/route-ratelimit.js @@ -2,9 +2,11 @@ This file will replace the original rate-limit.js file. Sets the rate limits for the anonymous and paid tiers. Current rate limits: -- 1000 points in 60 seconds -- 10 points per call for paid tier (100 RPM) -- 50 points per call for anonymous tier (20 RPM) +- 10000 points in 60 seconds +- 500 points per call for anonymous tier (20 RPM) +- 100 points per call for tier 40 (100 RPM) +- 40 points per call for tier 50 (250 RPM) +- 16 points per call for tier 60 (625 RPM) The rate limit handling is designed for these four use cases: - Users who want to buy a JWT token for 24 hour access. @@ -41,11 +43,10 @@ const redisOptions = { port: process.env.REDIS_PORT ? process.env.REDIS_PORT : 6379, host: process.env.REDIS_HOST ? process.env.REDIS_HOST : '127.0.0.1' } -console.log(`redisOptions: ${JSON.stringify(redisOptions, null, 2)}`) const redisClient = new Redis(redisOptions) const rateLimitOptions = { storeClient: redisClient, - points: 1000, // Number of points + points: config.pointsPerMinute, // Number of points duration: 60 // Per minute (per 60 seconds) } @@ -55,7 +56,7 @@ const ANON_LIMITS = config.anonRateLimit const WHITELIST_DOMAINS = config.whitelistDomains const WHITELIST_POINTS_TO_CONSUME = config.whitelistRateLimit const POINTS_PER_MINUTE = config.pointsPerMinute -const INTERNAL_POINTS_TO_CONSUME = 1 +const INTERNAL_POINTS_TO_CONSUME = 10 class RateLimits { constructor () { diff --git a/test/v4/rate-limit-unit.js b/test/v4/rate-limit-unit.js index 4c06e5b..6fec555 100644 --- a/test/v4/rate-limit-unit.js +++ b/test/v4/rate-limit-unit.js @@ -380,7 +380,7 @@ describe('#rate-routelimit', () => { assert.equal( res.locals.pointsToConsume, - 1, + 10, 'Internal rate limits applied' ) }) @@ -403,7 +403,7 @@ describe('#rate-routelimit', () => { assert.equal( res.locals.pointsToConsume, - 1, + 10, 'Internal rate limits applied' ) })