Skip to content

fix: use getClientIp in webhook endpoint to prevent IP spoofing (#6014)#6047

Merged
JhaSourav07 merged 7 commits into
JhaSourav07:mainfrom
atul-upadhyay-7:fix/webhook-ip-spoofing-vulnerability
Jun 21, 2026
Merged

fix: use getClientIp in webhook endpoint to prevent IP spoofing (#6014)#6047
JhaSourav07 merged 7 commits into
JhaSourav07:mainfrom
atul-upadhyay-7:fix/webhook-ip-spoofing-vulnerability

Conversation

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a security vulnerability where the webhook endpoint reads the client IP directly from x-forwarded-for instead of using the secure getClientIp() helper, making rate limiting trivially bypassable.

Changes

  1. Added getClientIp import ():

    • Imported getClientIp from @/utils/getClientIp
  2. Replaced direct header reading with getClientIp() ():

    • Changed from: const ip = req.headers.get('x-forwarded-for') || 'unknown_ip'
    • Changed to: const ip = getClientIp(req)
  3. Updated tests ():

    • Mocked getClientIp to return unique IPs per test
    • All 8 tests pass

Security Benefits

  • Prevents IP spoofing via x-forwarded-for header manipulation
  • Uses the same secure IP resolution as all other endpoints (middleware.ts, streak route, etc.)
  • Proper proxy chain analysis and spoofing detection
  • Rate limiting now works correctly based on the actual client IP

Issue

Fixes #6014

Testing

  • All 8 webhook tests pass
  • Linting passes with no new errors

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

@atul-upadhyay-7 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 status:blocked This PR is blocked due to a failing CI check. type:bug Something isn't working as expected labels Jun 19, 2026
@Aamod-Dev Aamod-Dev added level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:security Security fixes, dependency updates, or hardening mentor:Aamod007 labels Jun 20, 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.

This is a solid security fix — swapping the raw
eq.headers.get('x-forwarded-for')\ in \�pp/api/webhook/route.ts:38\ for the proper \getClientIp(req)\ helper, with comprehensive test mocks in
oute.test.ts\ for unique IPs per test case. Unfortunately this PR has \status:blocked\ (failing CI), so I can't approve it yet. Get those CI checks green and I'll be happy to approve!

@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.

Review

This PR cannot be approved in its current state due to blocking issues (status:blocked label, merge conflicts, needs-rebase label, and/or failing CI checks). Please resolve the blocking issues and re-request review.

Once unblocked, I'm happy to re-review! 💚

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jun 21, 2026
@github-actions

github-actions Bot commented Jun 21, 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 3697.00 KB 3697.00 KB 0 B
Total CSS 296.58 KB 296.58 KB 0 B

@Aamod-Dev Aamod-Dev added GSSoC 2026 security bug Something isn't working labels Jun 21, 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.

Using getClientIp() instead of directly reading the x-forwarded-for header in app/api/webhook/route.ts is crucial for preventing IP spoofing and rate limit bypasses. Refactoring app/api/webhook/route.test.ts to use a mocked getClientIp properly isolates the tests. Approved!

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jun 21, 2026
@JhaSourav07 JhaSourav07 merged commit 8657b34 into JhaSourav07:main Jun 21, 2026
8 of 9 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @atul-upadhyay-7! 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 this to the GSSoC 2026 milestone Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gssoc:approved PR has been reviewed and accepted for valid contribution points GSSoC 2026 level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. security 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.

Webhook rate limiter reads spoofable IP from x-forwarded-for instead of using getClientIp()

3 participants