Forward Proxy vs Reverse Proxy: Connection Paths, Trust Boundaries, and Latency
Forward Proxy vs Reverse Proxy: Connection Paths, Trust Boundaries, and Latency
Search
Ask the AI

Forward Proxy vs Reverse Proxy: Connection Paths, Trust Boundaries, and Latency

A forward proxy connects on behalf of a client; a reverse proxy receives requests on behalf of a service. Access controls, TLS termination, identity privacy and attack resistance depend on configuration. Map the connections, decryption points and identity propagation before deciding which components to trust.

Untrusted forwarding headers and inconsistent message framing can create source-spoofing or request-smuggling risks. This guide checks XFF trusted hops, SPIFFE identities, one kernel-function timing fragment and a single-server queue model, with their implementation and modeling conditions.

1. Beyond Basic Topologies: Transparent Interception and Sidecars

In a mesh, one sidecar can handle inbound and outbound proxy roles. Forward/reverse definitions still describe individual connections; transparent interception describes how traffic reaches the proxy, not a replacement for its trust boundary.

  • Envoy Sidecar: A mesh can redirect selected traffic with iptables and related mechanisms; protocols, ports and exclusion rules determine coverage. sockmap is a separate optional socket-acceleration mechanism, not the default interception mode of every mesh. mTLS needs the corresponding identity and policy configuration.
  • eBPF socket redirection: sockops can participate in socket-state handling; supported sockmap stream/message programs perform parsing or redirection. cgroup/skb is not a general replacement for forwarding arbitrary application buffers. Avoid inferring an overall change from \(O(N)\) to \(O(1)\) merely from fewer copies or less stack traversal.

Visualizing Cryptographic Trust Boundaries


graph TD
    subgraph Edge Network
        CDN[Edge CDN / WAF]
    end
    
    subgraph Kubernetes Cluster
        IG[Ingress Gateway (Envoy)]
        subgraph Pod A
            SA[Sidecar Proxy]
            AppA[Microservice A]
        end
        subgraph Pod B
            SB[Sidecar Proxy]
            AppB[Microservice B]
        end
    end
    
    SPIRE[SPIRE Server]
    
    CDN -->|Internet TLS| IG
    IG -->|mTLS via SPIFFE ID| SA
    SA -->|Localhost / sockmap| AppA
    SA -->|mTLS via SPIFFE ID| SB
    SB -->|Localhost| AppB
    
    SPIRE -.->|Issues Short-lived SVIDs| IG
    SPIRE -.->|Issues Short-lived SVIDs| SA
    SPIRE -.->|Issues Short-lived SVIDs| SB
    
    classDef trust fill:#d4edda,stroke:#28a745,stroke-width:2px;
    class SA,SB,AppA,AppB,IG,SPIRE trust;

2. Source Code Analysis: The X-Forwarded-For Vulnerability in C++

Untrusted forwarding headers cannot directly establish client identity. The original C++ shorthand involving ConnectionManagerImpl below is not pinned to a compilable Envoy version. Interpret it with the v1.36.0 XFF rules; choosing a trusted request address does not mean rewriting the underlying TCP peer.

If you blindly parse the first IP in X-Forwarded-For (XFF), a malicious payload like X-Forwarded-For: 127.0.0.1, 203.0.113.50 easily bypasses naive IP blocklists.


// Envoy's approach to determining the trusted client IP
// Source: envoy/source/common/http/conn_manager_utility.cc
void ConnectionManagerUtility::mutateRequestHeaders(
    Http::RequestHeaderMap& headers, Network::Connection& connection,
    const envoy::config::core::v3::HttpConnectionManager& config,
    const LocalInfo::LocalInfo& local_info) {
    
    // Determine the true remote address based on configured trusted hops
    uint32_t xff_num_trusted_hops = config.xff_num_trusted_hops();
    
    // Envoy securely iterates backwards through the XFF header list
    // skipping exactly `xff_num_trusted_hops` to find the true client IP.
    auto xff_address = utility::getLastAddressFromXFF(headers, xff_num_trusted_hops);
    
    if (xff_address != nullptr) {
        // Overwrite the remote address with the validated XFF IP
        connection.connectionInfoSetter().setRemoteAddress(xff_address);
    }
}

Choose the index from configuration: let \(H = [IP_1, IP_2, \ldots, IP_n]\) use one-based indices. The \(K\)th address from the right is n−K+1, not \(n-K\). In Envoy v1.36.0, use_remote_address=true with xff_num_trusted_hops=N>0 selects the Nth from the right; false selects the (N+1)th, with defined peer-address fallback for short lists. The trusted ingress chain must also be enforced. Earlier entries, including \(i < n-K\), are unverified rather than automatically proven malicious.

3. SPIFFE/SPIRE: Mathematical Identity Verification (Zero-Trust)

Network isolation, constrained proxy ingress and workload identity can complement each other. SPIFFE supports X.509-SVID and JWT-SVID. Validate the trust domain/bundle, SPIFFE ID, validity and credential-specific requirements, then apply authorization policy. mTLS proves private-key possession; JWT credentials also need their audience checks.

The ECDSA signing relation is \(s = k^{-1} (z + r d_A) \pmod n\). A generic Pollard-rho discrete-log attack on a group of order n has about \(O(\sqrt{n})\) work, roughly \(2^{128}\) for a 256-bit group order. That is not a rigorous bound on SPIFFE forgery probability, nor must every attacker solve a discrete logarithm. Key theft, issuance/attestation and validation failures also affect identity security.

4. eBPF: Microsecond-Level Boundary Profiling

curl can measure end-to-end phases, while eBPF supplies selected kernel-function or state-event timing. The retained fragment below times one entry/return of tcp_v4_conn_request, part of SYN request processing. It does not measure accept() waiting, network SYN-ACK RTT, proxy allocation or complete boundary latency.


// eBPF kprobe tracing proxy accept() latency
#include <linux/bpf.h>
#include <linux/tcp.h>

BPF_HASH(start_time, u32, u64);

int kprobe__tcp_v4_conn_request(struct pt_regs *ctx, struct sock *sk, struct sk_buff *skb) {
    u32 pid = bpf_get_current_pid_tgid();
    u64 ts = bpf_ktime_get_ns();
    start_time.update(&pid, &ts);
    return 0;
}

int kretprobe__tcp_v4_conn_request(struct pt_regs *ctx) {
    u32 pid = bpf_get_current_pid_tgid();
    u64 *tsp = start_time.lookup(&pid);
    if (tsp != 0) {
        u64 delta_us = (bpf_ktime_get_ns() - *tsp) / 1000;
        bpf_trace_printk("Proxy SYN-ACK latency: %d us\\n", delta_us);
        start_time.delete(&pid);
    }
    return 0;
}

The fragment needs a BCC loader and matching symbols/headers. Its low 32-bit ID is not a connection identifier and can be inadequate for concurrent interrupt-context calls. Backlog, SYN flooding and lock contention require their own events and counters; this duration alone does not predict an HTTP 504.

5. Mathematical Modeling of Proxy Latency and Queuing

To approximate one service stage with a stationary FCFS M/G/1 queue, assume Poisson arrivals, independent identically distributed service times independent of arrivals, a finite second moment and infinite buffering. The mean queue wait \(W_q\) then follows below. The \(M/M/1\) and \(M/D/1\) models are special cases; a real proxy event loop need not satisfy them.

$$ W_q = \frac{\lambda \mathbb{E}[S^2]}{2(1-\rho)} $$

Here \(\lambda\) is arrival rate, mean service time is 1/μ, and utilization \(\rho = \lambda \mu^{-1}\) must be below 1. The term \(\mathbb{E}[S^2]\) is the service-time second moment. With service distribution fixed, \(W_q\) diverges as \(\rho \to 1\). This describes high-utilization queue risk; it does not uniquely prescribe circuit breaking. Concurrency limits, queue limits, deadlines and rejection policies depend on the workload.

Engineering Trust-Boundary Checklist

  • Identity and ingress: Combine workload identity, mTLS, authorization and network isolation for the threat model. Check proxy-bypass paths and trust-bundle management.
  • eBPF Socket Acceleration: Evaluate Cilium or sockmap for the supported path and semantics, then measure the target workload. It is not a universal switch that removes all sidecar/proxy IPC overhead.
  • XFF trust: Check Envoy xff_num_trusted_hops together with use_remote_address and enforced ingress. For Nginx, set_real_ip_from also needs the matching trusted addresses, real_ip_header and recursive rules. Defaults and variable hop chains can change address selection.
  • Latency Distributions: Measure proxy latency via eBPF histograms, observing the 99.9th percentile (\(P_{99.9}\)).

Proxy Trust Boundary Evidence Matrix

To distinguish a forward proxy, reverse proxy, and sidecar, establish who sees client identity, who terminates TLS, who writes forwarding headers, and who owns access control. The matrix below lists evidence for checking those boundaries in production.

Check Evidence to collect Risk signal Fix direction
Client origin X-Forwarded-For, Forwarded, and true peer IP. The application trusts a forwarding header supplied by the user. Trust only the final header added by controlled reverse proxies.
TLS termination Certificate location, upstream protocol, and mTLS state. Traffic is decrypted at the edge and sent upstream in plaintext. Define mTLS or private-network isolation between edge and service.
Identity propagation SPIFFE ID, JWT audience, and sidecar injection policy. Multiple services share one identity or tokens can be replayed cross-service. Issue short-lived workload identity and validate audience.
Latency attribution Proxy hop count, queue depth, upstream timing, and eBPF latency histograms. All latency is blamed on a slow backend. Record client, proxy, upstream, and application timing separately.

References

Leave a Reply

Scroll down