Skip to content

Commit

Permalink
Implement disable_insecure_upstreams_check (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Jan 16, 2025
1 parent 8f8155f commit b9def71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ forward_proxy {
ports 80 443
hide_ip
hide_via
disable_insecure_upstreams_check
probe_resistance secret-link-kWWL9Q.com # alternatively you can use a real domain, such as caddyserver.com
serve_pac /secret-proxy.pac
Expand Down Expand Up @@ -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.

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

Expand Down
7 changes: 7 additions & 0 deletions caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
h.HideVia = true

case "disable_insecure_upstreams_check":
args := d.RemainingArgs()
if len(args) != 0 {
return d.ArgErr()
}
h.DisableInsecureUpstreamsCheck = true

case "probe_resistance":
args := d.RemainingArgs()
if len(args) > 1 {
Expand Down
5 changes: 4 additions & 1 deletion forwardproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type Handler struct {
// If true, the Via header will not be added.
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,
// you will give it the host (and port) of the proxy to use.
Hosts caddyhttp.MatchHost `json:"hosts,omitempty"`
Expand Down Expand Up @@ -191,7 +194,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
}
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")
}

Expand Down

0 comments on commit b9def71

Please sign in to comment.