Implement disable_insecure_upstreams_check (#149)

This commit is contained in:
Francis Lavoie 2025-01-16 11:47:57 -05:00 committed by GitHub
parent 8f8155f3c1
commit b9def71846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View file

@ -88,6 +88,7 @@ forward_proxy {
ports 80 443 ports 80 443
hide_ip hide_ip
hide_via hide_via
disable_insecure_upstreams_check
probe_resistance secret-link-kWWL9Q.com # alternatively you can use a real domain, such as caddyserver.com probe_resistance secret-link-kWWL9Q.com # alternatively you can use a real domain, such as caddyserver.com
serve_pac /secret-proxy.pac serve_pac /secret-proxy.pac
@ -133,6 +134,10 @@ forward_proxy {
Only this address will trigger a 407 response, prompting browsers to request credentials from user and cache them for the rest of the session. Only this address will trigger a 407 response, prompting browsers to request credentials from user and cache them for the rest of the session.
Default: no probing resistance. Default: no probing resistance.
- `disable_insecure_upstreams_check`
Disables the check for insecure (HTTP) upstreams. By default, forwardproxy will refuse to connect to upstreams that are not using TLS. This option disables that check.
Default: check for insecure upstreams.
### Privacy ### Privacy

View file

@ -99,6 +99,13 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
} }
h.HideVia = true h.HideVia = true
case "disable_insecure_upstreams_check":
args := d.RemainingArgs()
if len(args) != 0 {
return d.ArgErr()
}
h.DisableInsecureUpstreamsCheck = true
case "probe_resistance": case "probe_resistance":
args := d.RemainingArgs() args := d.RemainingArgs()
if len(args) > 1 { if len(args) > 1 {

View file

@ -64,6 +64,9 @@ type Handler struct {
// If true, the Via header will not be added. // If true, the Via header will not be added.
HideVia bool `json:"hide_via,omitempty"` HideVia bool `json:"hide_via,omitempty"`
// If true, the strict check preventing HTTP upstreams will be disabled.
DisableInsecureUpstreamsCheck bool `json:"disable_insecure_upstreams_check,omitempty"`
// Host(s) (and ports) of the proxy. When you configure a client, // Host(s) (and ports) of the proxy. When you configure a client,
// you will give it the host (and port) of the proxy to use. // you will give it the host (and port) of the proxy to use.
Hosts caddyhttp.MatchHost `json:"hosts,omitempty"` Hosts caddyhttp.MatchHost `json:"hosts,omitempty"`
@ -191,7 +194,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
} }
h.upstream = upstreamURL h.upstream = upstreamURL
if !isLocalhost(h.upstream.Hostname()) && h.upstream.Scheme != "https" { if !h.DisableInsecureUpstreamsCheck && !isLocalhost(h.upstream.Hostname()) && h.upstream.Scheme != "https" {
return errors.New("insecure schemes are only allowed to localhost upstreams") return errors.New("insecure schemes are only allowed to localhost upstreams")
} }