mirror of
https://github.com/caddyserver/caddy.git
synced 2025-11-02 18:47:22 -05:00
cmd: prevent commas in header values from being split (#7268)
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.25.0, ubuntu-latest, 0, 1.25, linux) (push) Failing after 1s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Cross-Build / build (~1.25.0, 1.25, aix) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, darwin) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, dragonfly) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, freebsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, illumos) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, linux) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, netbsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, openbsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, solaris) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, windows) (push) Failing after 1s
Lint / lint (ubuntu-latest, linux) (push) Failing after 0s
Lint / govulncheck (push) Failing after 0s
Lint / dependency-review (push) Failing after 0s
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Failing after 47s
Tests / test (./cmd/caddy/caddy, ~1.25.0, macos-14, 0, 1.25, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.25.0, windows-latest, True, 1.25, windows) (push) Has been cancelled
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.25.0, ubuntu-latest, 0, 1.25, linux) (push) Failing after 1s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Cross-Build / build (~1.25.0, 1.25, aix) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, darwin) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, dragonfly) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, freebsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, illumos) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, linux) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, netbsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, openbsd) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, solaris) (push) Failing after 0s
Cross-Build / build (~1.25.0, 1.25, windows) (push) Failing after 1s
Lint / lint (ubuntu-latest, linux) (push) Failing after 0s
Lint / govulncheck (push) Failing after 0s
Lint / dependency-review (push) Failing after 0s
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Failing after 47s
Tests / test (./cmd/caddy/caddy, ~1.25.0, macos-14, 0, 1.25, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.25.0, windows-latest, True, 1.25, windows) (push) Has been cancelled
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
`pflag.GetStringSlice` treats commas as delimiters, which causes issues when passing headers whose values contain commas (`X-Robots-Tag: noindex, nofollow`). These are incorrectly split into multiple headers and errors out: - `X-Robots-Tag: noindex` - ` nofollow` Switch to `pflag.GetStringArray`, which does not split on commas[1]. Note that this changes behavior for cases where multiple headers were provided in a single argument with commas (`--header-down "X-Foo: Bar,X-Bar: Foo"`). Such cases will now be treated as a single header value. If this breaking change is unacceptable, we will need a smarter fallback mechanism. [1] https://github.com/spf13/pflag/pull/90
This commit is contained in:
parent
39ace450de
commit
f5c3094050
@ -75,8 +75,8 @@ For proxying:
|
||||
cmd.Flags().BoolP("insecure", "", false, "Disable TLS verification (WARNING: DISABLES SECURITY BY NOT VERIFYING TLS CERTIFICATES!)")
|
||||
cmd.Flags().BoolP("disable-redirects", "r", false, "Disable HTTP->HTTPS redirects")
|
||||
cmd.Flags().BoolP("internal-certs", "i", false, "Use internal CA for issuing certs")
|
||||
cmd.Flags().StringSliceP("header-up", "H", []string{}, "Set a request header to send to the upstream (format: \"Field: value\")")
|
||||
cmd.Flags().StringSliceP("header-down", "d", []string{}, "Set a response header to send back to the client (format: \"Field: value\")")
|
||||
cmd.Flags().StringArrayP("header-up", "H", []string{}, "Set a request header to send to the upstream (format: \"Field: value\")")
|
||||
cmd.Flags().StringArrayP("header-down", "d", []string{}, "Set a response header to send back to the client (format: \"Field: value\")")
|
||||
cmd.Flags().BoolP("access-log", "", false, "Enable the access log")
|
||||
cmd.Flags().BoolP("debug", "v", false, "Enable verbose debug logs")
|
||||
cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdReverseProxy)
|
||||
@ -182,7 +182,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
|
||||
}
|
||||
|
||||
// set up header_up
|
||||
headerUp, err := fs.GetStringSlice("header-up")
|
||||
headerUp, err := fs.GetStringArray("header-up")
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid header flag: %v", err)
|
||||
}
|
||||
@ -204,7 +204,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
|
||||
}
|
||||
|
||||
// set up header_down
|
||||
headerDown, err := fs.GetStringSlice("header-down")
|
||||
headerDown, err := fs.GetStringArray("header-down")
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid header flag: %v", err)
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ Response headers may be added using the --header flag for each header field.
|
||||
cmd.Flags().StringP("body", "b", "", "The body of the HTTP response")
|
||||
cmd.Flags().BoolP("access-log", "", false, "Enable the access log")
|
||||
cmd.Flags().BoolP("debug", "v", false, "Enable more verbose debug-level logging")
|
||||
cmd.Flags().StringSliceP("header", "H", []string{}, "Set a header on the response (format: \"Field: value\")")
|
||||
cmd.Flags().StringArrayP("header", "H", []string{}, "Set a header on the response (format: \"Field: value\")")
|
||||
cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdRespond)
|
||||
},
|
||||
})
|
||||
@ -359,7 +359,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
|
||||
}
|
||||
|
||||
// build headers map
|
||||
headers, err := fl.GetStringSlice("header")
|
||||
headers, err := fl.GetStringArray("header")
|
||||
if err != nil {
|
||||
return caddy.ExitCodeFailedStartup, fmt.Errorf("invalid header flag: %v", err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user