From b88e0bc8f8b031ed53386bd4db5117a4eff0442e Mon Sep 17 00:00:00 2001 From: Benoit Plessis Date: Sat, 13 Nov 2021 01:34:19 +0100 Subject: [PATCH] Fix for Issue #501: Unexpected User-agent insertion when tunneling http request When forwarding an UA-less request to the origin server cloudflared insert the default golang http User-Agent, this is unexpected and can lead to issue. This simple fix force setting the UA to the empty string when it isn't originaly provided. --- origin/proxy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/origin/proxy.go b/origin/proxy.go index 00505fe0..53f10de3 100644 --- a/origin/proxy.go +++ b/origin/proxy.go @@ -177,6 +177,11 @@ func (p *Proxy) proxyHTTPRequest( roundTripReq.Header.Set("Connection", "keep-alive") } + // Set the User-Agent as an empty string if not provided to avoid inserting golang default UA + if roundTripReq.Header.Get("User-Agent") == "" { + roundTripReq.Header.Set("User-Agent", "") + } + resp, err := httpService.RoundTrip(roundTripReq) if err != nil { return errors.Wrap(err, "Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared")