From 49fce901262a4a2956be7ff7930b29ecd05cb7b9 Mon Sep 17 00:00:00 2001 From: Douglas Danger Manley Date: Thu, 26 Sep 2024 10:51:32 -0400 Subject: [PATCH] Support an unlimited rate limit everywhere Everywhere that `ratelimiter.New` is used, we now support `ratelimiter.NewUnlimited` when the value given is zero. In places that used to check to see that _both_ the numerator and the denominator were 0, they now only check to see if the numerator is zero. From a user perspective, the difference between 0 seconds, 0 milliseconds, and 0 hours is meaningless. It is clear that when they say zero, they mean zero. --- lib/config.go | 6 +++++- lib/multi.go | 2 +- lib/sdk_private.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/config.go b/lib/config.go index 7a9419aa50..ab2c283003 100644 --- a/lib/config.go +++ b/lib/config.go @@ -174,7 +174,11 @@ func WithGlobalRateLimitCtx(ctx context.Context, maxTokens int, duration time.Du return func(e *NucleiEngine) error { e.opts.RateLimit = maxTokens e.opts.RateLimitDuration = duration - e.rateLimiter = ratelimit.New(ctx, uint(e.opts.RateLimit), e.opts.RateLimitDuration) + if e.opts.RateLimit == 0 { + e.rateLimiter = ratelimit.NewUnlimited(ctx) + } else { + e.rateLimiter = ratelimit.New(ctx, uint(e.opts.RateLimit), e.opts.RateLimitDuration) + } return nil } } diff --git a/lib/multi.go b/lib/multi.go index 44c13ddfe6..fcf27e709c 100644 --- a/lib/multi.go +++ b/lib/multi.go @@ -48,7 +48,7 @@ func createEphemeralObjects(ctx context.Context, base *NucleiEngine, opts *types if opts.RateLimit > 0 && opts.RateLimitDuration == 0 { opts.RateLimitDuration = time.Second } - if opts.RateLimit == 0 && opts.RateLimitDuration == 0 { + if opts.RateLimit == 0 { u.executerOpts.RateLimiter = ratelimit.NewUnlimited(ctx) } else { u.executerOpts.RateLimiter = ratelimit.New(ctx, uint(opts.RateLimit), opts.RateLimitDuration) diff --git a/lib/sdk_private.go b/lib/sdk_private.go index cacd9a1ca1..81a4fb8dfd 100644 --- a/lib/sdk_private.go +++ b/lib/sdk_private.go @@ -208,7 +208,7 @@ func (e *NucleiEngine) init(ctx context.Context) error { if e.opts.RateLimit > 0 && e.opts.RateLimitDuration == 0 { e.opts.RateLimitDuration = time.Second } - if e.opts.RateLimit == 0 && e.opts.RateLimitDuration == 0 { + if e.opts.RateLimit == 0 { e.executerOpts.RateLimiter = ratelimit.NewUnlimited(ctx) } else { e.executerOpts.RateLimiter = ratelimit.New(ctx, uint(e.opts.RateLimit), e.opts.RateLimitDuration)