reverse proxy: validate versions in http transport

This commit is contained in:
WeidiDeng 2025-07-08 09:25:22 +08:00
parent 77dd12cc78
commit 6c272ec860
No known key found for this signature in database
GPG Key ID: 25F87CE1741EC7CD

View File

@ -171,12 +171,25 @@ func (HTTPTransport) CaddyModule() caddy.ModuleInfo {
}
}
var (
allowedVersions = []string{"1.1", "2", "h2c", "3"}
allowedVersionsString = strings.Join(allowedVersions, ", ")
)
// Provision sets up h.Transport with a *http.Transport
// that is ready to use.
func (h *HTTPTransport) Provision(ctx caddy.Context) error {
if len(h.Versions) == 0 {
h.Versions = []string{"1.1", "2"}
}
// some users may provide http versions not recognized by caddy, instead of trying to
// guess the version, we just error out and let the user fix their config
// see: https://github.com/caddyserver/caddy/issues/7111
for _, v := range h.Versions {
if !slices.Contains(allowedVersions, v) {
return fmt.Errorf("unsupported HTTP version: %s, supported version: %s", v, allowedVersionsString)
}
}
rt, err := h.NewTransport(ctx)
if err != nil {