Skip to content

fix: secure track-user ip rate limiting to prevent mongodb exhaustion - #2000

Merged
JhaSourav07 merged 3 commits into
JhaSourav07:mainfrom
riddhima25bet10005-a11y:fix-issue-1991
May 31, 2026
Merged

fix: secure track-user ip rate limiting to prevent mongodb exhaustion#2000
JhaSourav07 merged 3 commits into
JhaSourav07:mainfrom
riddhima25bet10005-a11y:fix-issue-1991

Conversation

@riddhima25bet10005-a11y

Copy link
Copy Markdown
Contributor

Description

Fixes #1991

This PR resolves the critical "Unauthenticated MongoDB Exhaustion / Denial of Wallet" vulnerability in the /api/track-user endpoint.

By default, the req.headers.get('x-forwarded-for') header can be easily spoofed by malicious clients. Vercel automatically appends the true client IP to the end of this header chain and also provides it securely in the x-real-ip header. This PR updates the rate-limiting logic to properly prioritize the un-spoofable edge-provided IP (x-real-ip or the last IP in the x-forwarded-for chain). This effectively blocks attackers from bypassing the trackUserRateLimiter to flood the MongoDB instance.

Pillar

  • dYZ" Pillar 1 ?" New Theme Design
  • dY"? Pillar 2 ?" Geometric SVG Improvement
  • dY ? Pillar 3 ?" Timezone Logic Optimization
  • dY>,? Other (Bug fix, refactoring, docs)

Visual Preview

N/A (Backend Security Fixes)

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the needs-rebase This PR has merge conflicts and needs a rebase. label May 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

27 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

4 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @riddhima25bet10005-a11y, this PR has merge conflicts with the main branch.

Please pull the latest changes and resolve the conflicts so we can review it!

git fetch origin
git rebase origin/main
# resolve any conflicts, then:
git push --force-with-lease

Once resolved, the needs-rebase label will be removed automatically on the next check. 🙌

@github-actions github-actions Bot added status:blocked This PR is blocked due to a failing CI check. and removed needs-rebase This PR has merge conflicts and needs a rebase. labels May 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @riddhima25bet10005-a11y, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label May 31, 2026
@riddhima25bet10005-a11y

Copy link
Copy Markdown
Contributor Author

Hi @JhaSourav07
All CI checks are green.
Kindly review and merge.
And kindly add a label for level of issue before merging.

@riddhima25bet10005-a11y

Copy link
Copy Markdown
Contributor Author

@Aamod007
Kindly merge

@JhaSourav07 JhaSourav07 added GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. quality:exceptional Outstanding contribution with exceptional implementation quality, testing. gssoc:approved PR has been reviewed and accepted for valid contribution points mentor:Aamod007 labels May 31, 2026
@github-actions github-actions Bot added this to the GSSoC 2026 milestone May 31, 2026
@JhaSourav07
JhaSourav07 merged commit 84e878f into JhaSourav07:main May 31, 2026
9 of 10 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @riddhima25bet10005-a11y! 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! 💻✨

@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jun 2, 2026
@JhaSourav07 JhaSourav07 added gssoc:approved PR has been reviewed and accepted for valid contribution points and removed gssoc:approved PR has been reviewed and accepted for valid contribution points labels Jun 17, 2026
MasterJi27 pushed a commit to MasterJi27/commitpulse that referenced this pull request Jul 4, 2026
…JhaSourav07#2000)

## Description

Fixes JhaSourav07#1991

This PR resolves the critical "Unauthenticated MongoDB Exhaustion /
Denial of Wallet" vulnerability in the `/api/track-user` endpoint.

By default, the `req.headers.get('x-forwarded-for')` header can be
easily spoofed by malicious clients. Vercel automatically appends the
true client IP to the end of this header chain and also provides it
securely in the `x-real-ip` header. This PR updates the rate-limiting
logic to properly prioritize the un-spoofable edge-provided IP
(`x-real-ip` or the last IP in the `x-forwarded-for` chain). This
effectively blocks attackers from bypassing the `trackUserRateLimiter`
to flood the MongoDB instance.

## Pillar

- [ ] dYZ" Pillar 1 ?" New Theme Design
- [ ] dY"? Pillar 2 ?" Geometric SVG Improvement
- [ ] dY ? Pillar 3 ?" Timezone Logic Optimization
- [x] dY>,? Other (Bug fix, refactoring, docs)

## Visual Preview
N/A (Backend Security Fixes)

## Checklist before requesting a review:

- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally
(`localhost:3000/api/streak?user=YOUR_USERNAME`).
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors (CI will fail otherwise).
- [x] My commits follow the Conventional Commits format (e.g.,
`feat(themes): ...`, `fix(calculate): ...`).
- [x] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have started the repo.
- [x] I have made sure that i have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse "premium quality" aesthetic
standard (no raw elements, smooth animations, correct fonts).
- [x] (Recommended) I joined the CommitPulse Discord community for
contributor discussions, mentorship, and faster PR support.
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 GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 quality:exceptional Outstanding contribution with exceptional implementation quality, testing. type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unauthenticated MongoDB Exhaustion / Denial of Wallet in /api/track-user

3 participants