Proxies sit in the path of almost every web request an organisation makes or receives, and a misconfigured one quietly becomes an open relay, an SSRF launch point or a source of forged client identity. A forward proxy acts for your users and workloads going out; a reverse proxy acts for your servers taking traffic in. They share software (NGINX, Apache httpd, HAProxy, Squid, Envoy) but have opposite trust models, and most proxy incidents come from confusing the two. This guide explains the roles, the specific risks of each, how to harden and log them, and how to roll changes out safely. It is written for network, platform and application security engineers who own or depend on proxy tiers, and it goes deeper than the Network Security Guide on this one component.
Key takeaways
- Direction defines the trust model. A forward proxy must restrict who can use it and where they can go; a reverse proxy must restrict which backends it reaches and which request headers it believes.
- Forwarding headers are claims, not facts. RFC 7239 states that the Forwarded header is not authoritative and can be changed by any node, including the client, so trust only values added by proxies you operate.
- The open proxy is still the classic failure. Apache's own documentation warns that open proxy servers are dangerous to your network and to the Internet at large; the same applies to unrestricted CONNECT tunnels.
- A reverse proxy is a privileged workload. It holds TLS private keys, routes to internal hosts and often carries a cloud role, so SSRF or a memory leak in it exposes far more than one application.
- Logs at the proxy are your best web telemetry. Done well, they record the true client, the identity, the destination and the TLS details for every request, which is what detection for T1090 and T1071.001 depends on.
Forward, reverse and transparent proxies compared
RFC 9110 defines a proxy as an intermediary chosen by the client, usually through local configuration, and a gateway (reverse proxy) as an intermediary that acts as the origin server for the outbound connection and forwards requests inbound to one or more other servers. A tunnel is a blind relay that does not change messages, which is what an HTTP CONNECT session becomes once established.
| Aspect | Forward proxy | Reverse proxy (gateway) | Transparent / intercepting proxy |
|---|---|---|---|
| Acts for | Clients: users, servers, workloads, agents going outbound | Origin servers receiving inbound traffic | Clients, without client configuration (traffic is redirected by the network) |
| Who knows it exists | Client (PAC file, WPAD, environment variables such as HTTPS_PROXY) | Server operator; the client believes it is the origin | Network operator only |
| Main security jobs | Egress control, URL and category filtering, malware scanning, data loss checks, user attribution | TLS termination, routing, WAF, rate limiting, hiding backend topology, authentication offload | Egress control where clients cannot be configured (guest, IoT) |
| Typical abuse | Open relay, CONNECT tunnelling to arbitrary ports, bypass by direct egress | Header spoofing, Host header routing SSRF, request smuggling, cache poisoning, exposed admin endpoints | Breaks certificate pinning and mutual TLS; hard to attribute users |
| Access control focus | Who may use it, which destinations and ports | Which hostnames and paths are published, which backends may be reached | Which networks are redirected, what is bypassed |
| Common software | Squid, secure web gateway services, Apache with ProxyRequests On | NGINX, HAProxy, Envoy, Apache with ProxyPass, cloud application gateways | Squid intercept mode, firewall web proxies |
Cloud and SASE products blur these lines: a secure web gateway is a managed forward proxy, and a CDN or application load balancer is a managed reverse proxy. The risks below still apply; only the configuration surface changes. See the Secure Web Gateway and Web Filtering Guide for the filtering policy side and the Load Balancer Security Guide for the L4/L7 balancing tier.
Threats by proxy role
| Threat | Role affected | What happens | Primary control | Reference |
|---|---|---|---|---|
| Open proxy abuse | Forward | Outsiders relay traffic through you, hiding their origin and attributing abuse to your IP space | Bind to internal interfaces, authenticate users, deny by default | ATT&CK T1090.002 External Proxy |
| Arbitrary CONNECT tunnels | Forward | CONNECT to SSH, SMTP or custom ports creates an unfiltered tunnel out | Allow CONNECT only to an SSL_ports list (usually 443) | T1572 Protocol Tunneling |
| C2 over web protocols | Forward | Malware beacons through the sanctioned proxy, blending with normal traffic | Category filtering, newly registered domain blocking, beacon analytics | T1071.001 Web Protocols, T1090.004 Domain Fronting |
| Internal proxy pivoting | Both | An attacker on one host relays traffic into segments it cannot reach directly | Segmentation, deny proxy software on endpoints, monitor east-west HTTP | T1090.001 Internal Proxy |
| Client IP spoofing | Reverse | Client sends its own X-Forwarded-For; app trusts it for rate limits, allowlists or audit | Overwrite or sanitise at the edge; trust only known proxy addresses | RFC 7239 s8 |
| Host header and routing SSRF | Reverse | Proxy routes on an attacker-supplied Host or X-Forwarded-Host to internal hosts | Explicit server_name / virtual host allowlist, default deny catch-all | T1190; PortSwigger Host header research |
| Request smuggling and desync | Reverse | Front end and backend parse message length differently; requests cross between users | Normalise or reject ambiguous requests, HTTP/2 end to end where possible | See the HTTP Request Smuggling Guide |
| Adversary in the middle | Both | Proxy re-encrypts with weak or no backend TLS; internal traffic readable | TLS or mTLS to backends with certificate validation | T1557; SP 800-53 SC-8 |
| Exploited proxy software | Both | Unpatched proxy is the internet-facing application | Patch to KEV deadlines, minimal modules, no exposed admin interfaces | CVE-2021-41773 (Apache httpd path traversal, in CISA KEV) |
For the detail behind two of these rows, see the HTTP Request Smuggling Guide and the Web Cache Poisoning and Cache Deception Guide.
Hardening a forward proxy
The forward proxy is the control point for outbound traffic, which makes it valuable only if traffic cannot go around it. NIST SP 800-53 SC-7(8) "Route Traffic to Authenticated Proxy Servers" captures the intent: outbound traffic of defined types goes through an authenticated proxy at managed interfaces.
- Close the bypass first: block direct outbound TCP 80 and 443 at the firewall for every network that should use the proxy, and allow it only from the proxy's own addresses. Without this, filtering is advisory. Treat DNS over HTTPS to public resolvers the same way.
- Restrict who can use it: listen only on internal interfaces, and limit source networks with ACLs. Apache httpd's mod_proxy documentation says it is essential to secure the server so only authorised clients can use a forward proxy before activating one, using
<Proxy "*">blocks withRequirerules. - Restrict ports and methods: in Squid, keep
http_access deny !Safe_portsandhttp_access deny CONNECT !SSL_portsnear the top of the configuration. Squid's guidance warns never to add port 25 to Safe_ports, which would turn the proxy into a mail relay. - Mind rule order: Squid evaluates
http_accesstop to bottom. An allow for a custom port placed abovedeny !localnetexposes the proxy publicly. Combine conditions (http_access allow localnet mycoolapp) rather than adding broad allows. - Protect management functions: the Squid cache manager can show configuration, logged-in users and network layout, and can shut the service down. Keep the default
http_access allow localhost managerfollowed byhttp_access deny managerat the top, or narrow it to a management network. - Authenticate users and workloads: use Kerberos or the identity provider for people, and per-workload credentials or source identity for servers, so every log line names a principal. A shared proxy account used by many servers removes attribution.
- Filter destinations by policy: block uncategorised and newly registered domains, raw IP destinations and known anonymiser networks; allow only required SaaS for server networks rather than the whole web.
- Decide on TLS inspection explicitly: CONNECT tunnels are opaque unless you decrypt. Decrypt by category with clear exemptions (health, banking, pinned applications) and a privacy assessment. See the TLS Inspection Guide.
Hardening a reverse proxy
Apache's documentation notes that a reverse proxy configured with ProxyPass and ProxyRequests Off is safer because clients can only reach hosts you have explicitly configured. That is the core design rule: the reverse proxy should publish a fixed, reviewed map of hostname and path to backend, and nothing else.
Routing and exposure
- Never enable forward proxying on a reverse proxy:
ProxyRequests Offin Apache; in NGINX, never buildproxy_passtargets from request variables such as$hostor$arg_urlwithout a fixed allowlist map. - Default deny virtual host: add a catch-all server block that rejects unknown Host values (for example returning 444 in NGINX or a static 421/404) so requests for internal names cannot be routed by guessing. PortSwigger's Host header research recommends forwarding only to allowlisted domains and not hosting internal-only virtual hosts on the same server as public content.
- Disable override headers you do not need: do not let backends honour
X-Forwarded-HostorX-Original-URLfrom clients. Strip them at the edge and set them yourself. - Keep admin paths off the public listener: status pages (
stub_status, HAProxy stats, Envoy admin on its own port) should bind to localhost or a management network only.
Headers and client identity
- Edge proxy overwrites, inner proxies append: the first proxy you control should replace any client-supplied
X-Forwarded-For,X-Real-IPandForwardedvalues. RFC 7239 is explicit that these values can be altered by any node, including the client, and that addresses added before the first trusted proxy cannot be verified. - Trust by address, not by header: NGINX's realip module uses the header only when the connection comes from an address listed in
set_real_ip_from. Withreal_ip_recursive on, it takes the last address in the chain that is not trusted, which is the correct client when every hop is listed; with it off, it takes the last address, which is often your own proxy. - Prefer the PROXY protocol for TCP hops: when a layer 4 balancer sits in front, pass the client address in the PROXY protocol header and accept it only on listeners reachable solely from that balancer, because a listener that accepts it from anyone lets clients forge their address.
- Avoid leaking topology: RFC 7239 recommends obfuscated node identifiers, warns against copying the header into responses and flags TRACE as a way to echo it back. Disable TRACE, remove
ServerandViadetail where it reveals internal names, and stripX-Powered-Byfrom backend responses. See the Security Headers Guide for response headers to add. - Treat client IP as personal data: RFC 7239 highlights that client addresses can identify a user and location, so keep logging retention and access aligned with your privacy policy.
Protocol handling and TLS
- Reject ambiguous requests: requests carrying both Content-Length and Transfer-Encoding, duplicate Content-Length, or invalid header characters should be rejected at the edge, not normalised differently by each hop.
- Set sane limits: header size, body size, request rate and timeouts (for example
client_max_body_size,large_client_header_buffers,proxy_read_timeoutin NGINX) bound the cost of slow and large request attacks. - Re-encrypt to backends and validate: enable
proxy_ssl_verify onwith a trusted CA andproxy_ssl_name, or mutual TLS where backends must know which proxy is calling. Plain HTTP across a flat internal network is an adversary-in-the-middle opportunity (T1557). See the mTLS Guide. - Limit egress from the proxy itself: a reverse proxy should reach only its backends. Block access to cloud metadata endpoints (169.254.169.254) unless needed and require IMDSv2 on AWS, so an SSRF in the proxy or WAF tier cannot fetch role credentials.
Where identity fits
Proxies are full of non-human identities, and they are often the least governed. A reverse proxy holds private keys for every hostname it terminates, frequently runs with a cloud role, and may carry client certificates or API keys to call backends. A forward proxy often has a shared service account in the directory for Kerberos, plus credentials for upstream filtering or threat intelligence services.
- Scope the proxy's cloud role to what it does: the Capital One breach is the reference case: SSRF through a misconfigured WAF fetched the WAF's own role credentials, and that role could list and read S3 buckets it never needed.
- Treat sessions issued at the proxy as credentials: when a gateway handles authentication, its session cookies are bearer tokens. In CitrixBleed a memory leak on the NetScaler gateway returned valid session cookies that bypassed MFA, and patching did not revoke the stolen ones.
- Rotate and inventory keys and certificates: keep TLS keys in an HSM or secrets manager where the platform allows, and track expiry and owners. See the Machine Identity, PKI and Certificate Lifecycle Guide.
- Give each workload its own proxy credential: per-workload identity on the forward proxy makes egress policy and investigation possible. See the Service Account Security Guide.
Choosing a design
- Explicit vs transparent forward proxy: explicit (PAC, WPAD or environment variables) gives clean user authentication and CONNECT visibility; transparent suits devices you cannot configure but loses user identity and breaks pinned or mutually authenticated applications. Most organisations run explicit for managed endpoints and servers, transparent only for guest and IoT segments.
- On-premises proxy vs cloud secure web gateway: a cloud gateway covers remote users without backhaul and is patched by the provider; an on-premises proxy keeps server egress and decrypted content inside your boundary. Many run both: cloud for users, local for data centre and build servers. See the SASE and SSE Guide.
- Self-managed reverse proxy vs managed gateway or CDN: self-managed gives full control of headers and routing and suits complex internal estates; managed services remove patching of an internet-facing appliance and add DDoS capacity, at the cost of a provider in your TLS path.
- One tier or two: a single reverse proxy is simpler to reason about; a CDN plus regional proxy plus service mesh adds parsing differences between hops, so test smuggling and header trust across the whole chain.
- Small organisations: use a managed gateway for users, a single well-maintained reverse proxy or cloud application gateway for public apps, and spend effort on blocking direct egress and on logging, which give most of the value.
- Large organisations: standardise proxy configuration as code, publish an approved header contract (which headers the edge sets, which backends may trust), and run conformance tests on every change.
Implementation: a phased rollout
- Inventory: list every proxy, its role, listeners, upstreams, certificates, credentials and owner, including sidecars and ingress controllers. Scan your public ranges for open proxy behaviour and exposed admin ports.
- Baseline configuration: write a standard for each role covering the controls above, stored as code, and diff every existing proxy against it.
- Logging first: before tightening, enable full access logs (client, authenticated user, method, host, path, status, bytes, upstream, TLS version and SNI) and ship them to the SIEM, so you can see what tightening will break.
- Forward proxy tightening in rings: enable authentication and port restrictions in monitor or log-only mode where the product supports it, then enforce for an IT pilot, then by business unit. Block direct egress per network segment only once its traffic is seen through the proxy.
- Reverse proxy header contract: deploy edge sanitisation of forwarding headers and the default-deny virtual host to a staging environment, run smuggling and Host header tests, then roll out one hostname at a time.
- Backend TLS: introduce certificate validation to backends per service, with an alert on handshake failures, before switching off plaintext listeners.
- Rollback: keep the previous configuration version deployable in one step, use canary instances behind the balancer, and define the error-rate threshold that triggers rollback before each change.
Detection and measurement
Proxy logs underpin detection of web-based command and control and of proxy abuse. Useful detections include long-lived CONNECT sessions to rare destinations, regular beacon intervals to one domain, requests to raw IP addresses, CONNECT attempts to non-443 ports (blocked or not), user agents that do not match the endpoint's managed software, unknown Host values hitting the default virtual host, and requests carrying both Content-Length and Transfer-Encoding. On endpoints, alert on new local proxy listeners and on changes to system proxy settings, which can indicate T1090.001 internal proxy setup.
| Metric | What it shows | Target |
|---|---|---|
| Share of outbound web traffic that passes through the proxy | Whether the bypass is closed | Close to 100% for managed networks |
| Proxy log lines with an authenticated principal | Attribution quality | Above 95% for user networks |
| Public proxy listeners failing the open-proxy and admin-port scan | Exposure | Zero |
| Reverse proxies passing the header contract and smuggling tests | Header trust and parsing consistency | All, re-tested on each release |
| Days to patch a proxy vulnerability listed in CISA KEV | Exposure window on internet-facing software | Within the KEV due date or your stricter SLA |
| Backend connections with verified TLS | Protection of the proxy-to-origin hop | Rising to 100% of sensitive services |
Common failure patterns
- Forward proxying left on a reverse proxy: a ProxyRequests On line copied from an example turns a web server into an open relay that scanners find within days.
- Trusting the leftmost X-Forwarded-For: rate limits, IP allowlists and audit logs keyed on a client-supplied value let attackers impersonate any address, including internal ones that bypass checks.
- Filtering without blocking direct egress: the proxy shows a clean picture while malware and shadow tools leave directly on 443.
- Overprivileged proxy and WAF roles: an SSRF in the edge tier becomes a data breach when the instance role can read storage, as in the Capital One breach.
- Patching without session revocation: after a gateway memory disclosure such as CitrixBleed, stolen session tokens keep working until sessions are killed.
- Plain HTTP behind TLS termination: the padlock covers only the first hop, while credentials and tokens cross the internal network unencrypted.
Framework mapping
| Framework | Reference | How it applies to proxies |
|---|---|---|
| NIST CSF 2.0 | PR.IR-01, PR.DS-02, PR.PS-01, DE.CM-01 | Network access protection, data in transit, configuration management, network monitoring |
| NIST SP 800-53 Rev. 5 | SC-7, SC-7(8), SC-8, SC-23, CM-7, AU-2, AU-12, SI-4 | Boundary protection, authenticated proxies, transmission protection, session authenticity, least functionality, logging and monitoring |
| CIS Controls v8.1 | 9.3, 13.10 | Network-based URL filters; application layer filtering |
| ISO/IEC 27001:2022 Annex A | A.8.20, A.8.22, A.8.23, A.8.24, A.8.15 | Networks security, segregation, web filtering, cryptography, logging |
| MITRE ATT&CK v20 | T1090 (.001 to .004), T1572, T1071.001, T1190, T1557 | Proxy and tunnelling abuse, web C2, exploitation of the proxy, interception |
Practitioner checklist
- Inventory every forward, reverse and transparent proxy with owner, listeners, upstreams, certificates and credentials.
- Block direct outbound web traffic from networks that should use the forward proxy, and measure the share that goes through it.
- Restrict forward proxy use to authenticated internal clients, and allow CONNECT only to an approved port list.
- Confirm no reverse proxy has forward proxying enabled, and add a default-deny virtual host for unknown Host values.
- Overwrite client-supplied forwarding headers at the edge and trust them downstream only from listed proxy addresses.
- Bind admin and status interfaces to management networks and scan public ranges for exposure.
- Re-encrypt and validate TLS to backends, and block proxy access to cloud metadata endpoints.
- Scope proxy and WAF cloud roles to what they need, and rotate keys, certificates and service account credentials.
- Ship full proxy logs to the SIEM with detections for beacons, odd CONNECT ports and ambiguous requests.
- Patch proxy software to CISA KEV deadlines and revoke sessions after any memory disclosure.
Standards and references
- IETF: RFC 9110 HTTP Semantics
- IETF: RFC 7239 Forwarded HTTP Extension
- NIST: SP 800-53 Rev. 5
- NIST: Cybersecurity Framework 2.0
- Apache HTTP Server: mod_proxy documentation
- NGINX: ngx_http_realip_module
- Squid: Security Pitfalls
- MITRE ATT&CK: Proxy
Related NHI Mgmt Group resources: Network Security Guide · Load Balancer Security Guide · Secure Web Gateway and Web Filtering Guide · SSRF Prevention Guide · Web Application Firewall Guide