ProxyBridge icon indicating copy to clipboard operation
ProxyBridge copied to clipboard

fix: exclude loopback from NFQUEUE interception on Linux

Open rsyuzyov opened this issue 5 months ago • 1 comments

Pull Request Details

Type of Change

  • [x] Bug Fix

Related GitHub Issue

Issue Link: https://github.com/InterceptSuite/ProxyBridge/issues/164

Closes #164

Platform(s) Affected

  • [x] Linux

macOS Application Changes

Does this pull request include changes to the macOS application?

  • [x] No

Description of Changes

What does this pull request do?

Fixes heavy loopback (127.0.0.0/8) transfers stalling on Linux whenever ProxyBridge is active. ProxyBridge sent every OUTPUT packet — including loopback — through NFQUEUE and reinjected it; because lo has a 65536 MTU, loopback uses ~64 KB TCP segments that don't survive the NFQUEUE -> userspace -> reinject path, so non-trivial local responses timed out with 0 bytes (small responses and external traffic were unaffected). It reproduced even with no rules and no proxy configured, i.e. it was the interception itself.

The fix inserts -A OUTPUT -o lo -j ACCEPT in mangle/OUTPUT before the NFQUEUE rules so loopback bypasses the queue entirely, and removes it symmetrically in both cleanup paths (ProxyBridge_Stop and the library destructor used by --cleanup). Loopback is never proxied in the default configuration; this matches the Windows default (localhost is DIRECT unless LocalhostViaProxy is enabled).

Scope is intentionally minimal: 3 insertions of the same idiom (setup + two cleanup paths), IPv4 only (-o lo covers 127.0.0.0/8; the project does not use ip6tables).

How has this been tested?

  • Test environment: Debian 13 (trixie), x86_64, built from this branch.
  • Test steps: reproduce per the linked issue (16 MB file over 127.0.0.1:8080), with interception active, before and after the fix; plus a proxy regression through a SOCKS5 server.
  • Test results:
    Scenario (interception active) Before After
    loopback big.bin (16 MB) timeout, 0 bytes 200, 0.014 s
    loopback small request 200 200
    external ifconfig.me 200 200
    *:*:*:TCP:PROXY via SOCKS5 (exit IP) n/a routed through proxy, loopback still 200
    --cleanup removes NFQUEUE rules also removes the -o lo rule (no leftovers)

Compilation & Dependencies

  • [x] My changes compile without errors
  • [x] My changes do not introduce new dependencies

Additional Context

Authorship disclosure. I want to be fully transparent: I am not a C developer and could not have investigated or fixed this issue on my own. The root-cause analysis and the fix were done entirely by Claude Code (Opus 4.8). I made a genuine effort to understand the change and to verify that it is correct — see the reproduction and the before/after testing above, including a SOCKS5 proxy regression — but the decision is entirely yours: accept this PR as-is, request changes, or implement the fix yourselves. I am completely fine with any outcome; I would simply rather be upfront than present this as my own work.


Final Checklist

  • [x] My code follows the project's coding style
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] My changes do not generate new warnings or errors
  • [x] I have tested my changes on the target platform(s)
  • [x] I have verified this change is based on the latest dev branch
  • [x] I understand that pull requests without an associated GitHub issue will be rejected

rsyuzyov avatar Jun 12 '26 09:06 rsyuzyov