Skip to content

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

Open
atul-upadhyay-7 wants to merge 6 commits into
JhaSourav07:mainfrom
atul-upadhyay-7:fix/webhook-ip-spoofing-vulnerability
Open

fix: use getClientIp in webhook endpoint to prevent IP spoofing (#6014)#6047
atul-upadhyay-7 wants to merge 6 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

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 3694.34 KB 3694.34 KB 0 B
Total CSS 296.06 KB 296.06 KB 0 B

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

Labels

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.

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

2 participants