Skip to content

fix: prevent rate limiter quota leak on limit exceeded (#5895)#5932

Merged
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
vipul674:fix/ratelimiter-quota-leak
Jun 18, 2026
Merged

fix: prevent rate limiter quota leak on limit exceeded (#5895)#5932
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
vipul674:fix/ratelimiter-quota-leak

Conversation

@vipul674

Copy link
Copy Markdown
Contributor

Fixes #5895

Problem

When using Upstash Redis/KV, the rate limiter used INCR to increment the counter before checking if the limit was exceeded. This meant rejected requests still consumed quota, effectively lowering the rate limit below the configured value.

For example, with limit=10, if a user makes 10 requests (counter=10), the 11th request would:

  1. INCR → counter becomes 11
  2. Check: 11 > 10 → reject

But now the counter is 11, meaning the user is permanently one request over the limit until the window resets.

Fix

Check the current count first using GET + TTL, and only INCR if the count is below the limit. Rejected requests no longer consume quota.

When using KV, the INCR command incremented the counter before checking
the limit, causing rejected requests to still consume quota. This
meant the rate limiter effectively had a lower limit than configured.

Now checks the current count first and only increments if under the limit.

Fixes JhaSourav07#5895
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@vipul674 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vipul674

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 Ready for review.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3628.47 KB 3628.47 KB 0 B
Total CSS 284.92 KB 284.92 KB 0 B

@vipul674

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 Review Reminder

@Aamod-Dev Aamod-Dev added level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected type:security Security fixes, dependency updates, or hardening mentor:Aamod007 labels Jun 18, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Difficulty: intermediate – Changes rate-limit.ts to GET+check before INCR, preventing quota leak when limit exceeded (39 additions, 12 deletions).

Quality: clean – Fixes INCR-on-rejection bug.

Type: bug + security – Prevents rate limiter bypass issue #5895.

Important security fix!

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jun 18, 2026
@JhaSourav07 JhaSourav07 merged commit a7758b4 into JhaSourav07:main Jun 18, 2026
10 of 11 checks passed
@github-actions github-actions Bot added this to the GSSoC 2026 milestone Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @vipul674! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected type:security Security fixes, dependency updates, or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Refresh rate limiter consumes quota on cooldown-blocked refreshes

3 participants