mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-13 09:06:41 +00:00
forward_auth: copy_headers does not strip client-supplied identity headers (Fixes GHSA-7r4p-vjf4-gxv4) (#7545)
When using copy_headers in a forward_auth block, client-supplied headers with the same names were not being removed before being forwarded to the backend. This happens because PR #6608 added a MatchNot guard that skips the Set operation when the auth service does not return a given header. That guard prevents setting headers to empty strings, which is the correct behavior, but it also means a client can send X-User-Id: admin in their request and if the auth service validates the token without returning X-User-Id, Caddy skips the Set and the client value passes through unchanged to the backend. The fix adds an unconditional delete route for each copy_headers entry, placed just before the existing conditional set route. The delete always runs regardless of what the auth service returns. The conditional set still only runs when the auth service provides that header. The end result is: - Client-supplied headers are always removed - When the auth service returns the header, the backend gets that value - When the auth service does not return the header, the backend sees nothing Existing behavior is unchanged for any deployment where the auth service returns all of the configured copy_headers entries. Fixes GHSA-7r4p-vjf4-gxv4
This commit is contained in:
parent
dc36082859
commit
2dbcdefbbe
5 changed files with 480 additions and 2 deletions
|
|
@ -208,6 +208,24 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
|
|||
for _, from := range sortedHeadersToCopy {
|
||||
to := http.CanonicalHeaderKey(headersToCopy[from])
|
||||
placeholderName := "http.reverse_proxy.header." + http.CanonicalHeaderKey(from)
|
||||
|
||||
// Always delete the client-supplied header before conditionally setting
|
||||
// it from the auth response. Without this, a client that pre-supplies a
|
||||
// header listed in copy_headers can inject arbitrary values when the auth
|
||||
// service does not return that header: the MatchNot guard below would
|
||||
// skip the Set entirely, leaving the original client-controlled value
|
||||
// intact and forwarding it to the backend.
|
||||
copyHeaderRoutes = append(copyHeaderRoutes, caddyhttp.Route{
|
||||
HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(
|
||||
&headers.Handler{
|
||||
Request: &headers.HeaderOps{
|
||||
Delete: []string{to},
|
||||
},
|
||||
},
|
||||
"handler", "headers", nil,
|
||||
)},
|
||||
})
|
||||
|
||||
handler := &headers.Handler{
|
||||
Request: &headers.HeaderOps{
|
||||
Set: http.Header{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue