Skip to content

fix(security): take the client address from the socket in payment-method correction - #1628

Merged
itsbkm merged 1 commit into
mainfrom
fix/payment-correction-client-ip
Nov 25, 2026
Merged

itsbkm merged 1 commit into
mainfrom
fix/payment-correction-client-ip

Conversation

@itsbkm

@itsbkm itsbkm commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The payment-method correction route fell back to a client-supplied x-forwarded-for header when req.ip was empty, and that value keys the approval-PIN rate limit. It now uses req.ip || req.socket.remoteAddress, matching the other payment routes. Practical exposure was low: trust proxy is not set, so req.ip normally wins.
  • The LAN integrity suite now fails if any file under main/ mentions x-forwarded-for or x-real-ip. The check failed before the fix and passes after it.

Verification

  • npm run lint, npm run build, test:secure-network-lan-integrity, test:refund-completed-orders, test:integration-payments, test:financial-safety-remediation exit 0; git diff --check clean.
  • The full npm test was not run locally.

🤖 Generated with Claude Code

…hod correction

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Use socket-derived addresses for payment correction PIN limits

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Remove the client-supplied forwarding-header fallback from payment-method correction PIN rate
 limiting.
• Add a backend source check to prevent forwarding headers from being used for client addresses.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed rate-limit decision is part of the single end-to-end payment-method-correction operation: the route verifies an owner/manager PIN before changing a paid bill's payment method.
  • No separate consumer or independent functional scope was found for this rate-limit key; other rate-limit call sites use their own keys and do not consume this behavior.
Sources

main/routes/bills.ts[5532-5535]

      const clientIp = req.ip || req.socket.remoteAddress || 'unknown';
      const canonicalIp = normalizeIpForRateLimit(clientIp);
      const rateLimitKey = `pin:${canonicalIp}:payment-method-correction`;
      if (isPinRateLimited(rateLimitKey)) {
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the rate-limit identity could use req.ip, then a client-supplied x-forwarded-for header, then the socket address.
  • After, it uses req.ip or the socket address only.
  • The new correctness condition is that the PIN rate-limit bucket must be based on the server-observed request address rather than a forgeable forwarding header.
  • This is a direct selection-rule change; it introduces no new algorithm, state machine, concurrency protocol, transformation, or coordinated invariant.
Sources

main/routes/bills.ts[5532-5535]

      const clientIp = req.ip || req.socket.remoteAddress || 'unknown';
      const canonicalIp = normalizeIpForRateLimit(clientIp);
      const rateLimitKey = `pin:${canonicalIp}:payment-method-correction`;
      if (isPinRateLimited(rateLimitKey)) {
Potential damage 🟡 Medium 🩹 Temporary loss

  • Conditionally, if multiple legitimate clients are represented by the same reverse-proxy socket address and Express is not configured to derive distinct trusted client IPs, one client's failed PIN attempts could consume the shared bucket and temporarily prevent another client from correcting a payment method.
  • The consequence is limited to access to this operation and is recoverable after the rate-limit window expires or the in-memory limiter is cleared; the change does not itself alter persistent bill state or create external financial effects.
  • Revert would restore the prior address-selection behavior, but existing in-memory rate-limit entries may remain until expiry.
  • Normal recovery is waiting for the approximately 15-minute PIN lockout window or clearing the in-memory rate-limit state; no automatic repair of persistent data is required.
Sources

main/routes/bills.ts[5532-5535]

      const clientIp = req.ip || req.socket.remoteAddress || 'unknown';
      const canonicalIp = normalizeIpForRateLimit(clientIp);
      const rateLimitKey = `pin:${canonicalIp}:payment-method-correction`;
      if (isPinRateLimited(rateLimitKey)) {

main/routes/bills.ts[5545-5546]

        if (isPinRateLimited(rateLimitKey)) {
          return { rateLimited: true as const };
Assessed commit b17e95f
Diagram

graph TD
  Socket["Client socket"] --> Address["Request address"] --> Route["Payment correction"] --> Normalize["IP normalization"] --> Limit["PIN rate limit"]
  Guard["Source check"] -->|scans| Route
Loading
High-Level Assessment

Keep the focused fallback change: it matches the other payment routes without changing proxy trust settings. A shared address helper would add abstraction for a one-line convention; the source check guards against reintroducing header-based reads.

Files changed (2) +13 / -5

Bug fix (1) +1 / -5
bills.tsRemove the forwarding-header fallback from correction PIN limits +1/-5

Remove the forwarding-header fallback from correction PIN limits

• Payment-method correction now derives its rate-limit address from req.ip or the socket remote address, falling back to 'unknown' if neither exists. It no longer accepts a client-supplied x-forwarded-for value for this key.

main/routes/bills.ts

Tests (1) +12 / -0
secure-network-lan-integrity.test.tsReject forwarding-header references in backend TypeScript +12/-0

Reject forwarding-header references in backend TypeScript

• Adds an assertion that recursively scans .ts files under main/ for x-forwarded-for or x-real-ip and fails if either appears. The assertion runs before the suite’s LAN-interface check, so it also runs on machines without a private LAN interface.

tests/secure-network-lan-integrity.test.ts

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@itsbkm
itsbkm merged commit a6a24b4 into main Nov 25, 2026
39 of 41 checks passed
@itsbkm
itsbkm deleted the fix/payment-correction-client-ip branch November 25, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant