mirror of
https://github.com/caddyserver/caddy.git
synced 2026-03-17 14:34:03 +00:00
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
267 lines
5.3 KiB
Plaintext
267 lines
5.3 KiB
Plaintext
:8881
|
|
|
|
forward_auth localhost:9000 {
|
|
uri /auth
|
|
copy_headers A>1 B C>3 {
|
|
D
|
|
E>5
|
|
}
|
|
}
|
|
----------
|
|
{
|
|
"apps": {
|
|
"http": {
|
|
"servers": {
|
|
"srv0": {
|
|
"listen": [
|
|
":8881"
|
|
],
|
|
"routes": [
|
|
{
|
|
"handle": [
|
|
{
|
|
"handle_response": [
|
|
{
|
|
"match": {
|
|
"status_code": [
|
|
2
|
|
]
|
|
},
|
|
"routes": [
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "vars"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"delete": [
|
|
"1"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"set": {
|
|
"1": [
|
|
"{http.reverse_proxy.header.A}"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"match": [
|
|
{
|
|
"not": [
|
|
{
|
|
"vars": {
|
|
"{http.reverse_proxy.header.A}": [
|
|
""
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"delete": [
|
|
"B"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"set": {
|
|
"B": [
|
|
"{http.reverse_proxy.header.B}"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"match": [
|
|
{
|
|
"not": [
|
|
{
|
|
"vars": {
|
|
"{http.reverse_proxy.header.B}": [
|
|
""
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"delete": [
|
|
"3"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"set": {
|
|
"3": [
|
|
"{http.reverse_proxy.header.C}"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"match": [
|
|
{
|
|
"not": [
|
|
{
|
|
"vars": {
|
|
"{http.reverse_proxy.header.C}": [
|
|
""
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"delete": [
|
|
"D"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"set": {
|
|
"D": [
|
|
"{http.reverse_proxy.header.D}"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"match": [
|
|
{
|
|
"not": [
|
|
{
|
|
"vars": {
|
|
"{http.reverse_proxy.header.D}": [
|
|
""
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"delete": [
|
|
"5"
|
|
]
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"handle": [
|
|
{
|
|
"handler": "headers",
|
|
"request": {
|
|
"set": {
|
|
"5": [
|
|
"{http.reverse_proxy.header.E}"
|
|
]
|
|
}
|
|
}
|
|
}
|
|
],
|
|
"match": [
|
|
{
|
|
"not": [
|
|
{
|
|
"vars": {
|
|
"{http.reverse_proxy.header.E}": [
|
|
""
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"handler": "reverse_proxy",
|
|
"headers": {
|
|
"request": {
|
|
"set": {
|
|
"X-Forwarded-Method": [
|
|
"{http.request.method}"
|
|
],
|
|
"X-Forwarded-Uri": [
|
|
"{http.request.uri}"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"rewrite": {
|
|
"method": "GET",
|
|
"uri": "/auth"
|
|
},
|
|
"upstreams": [
|
|
{
|
|
"dial": "localhost:9000"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|