From 5ed8689629ed88832f015cb507332adde03faabe Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Tue, 5 Mar 2024 17:25:38 -0500 Subject: [PATCH] vars: Allow overriding `http.auth.user.id` in replacer as a special case (#6108) --- modules/caddyhttp/vars.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/caddyhttp/vars.go b/modules/caddyhttp/vars.go index 917a150513f..f5afe264a28 100644 --- a/modules/caddyhttp/vars.go +++ b/modules/caddyhttp/vars.go @@ -57,6 +57,12 @@ func (m VarsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next H v = repl.ReplaceAll(valStr, "") } vars[keyExpanded] = v + + // Special case: the user ID is in the replacer, pulled from there + // for access logs. Allow users to override it with the vars handler. + if keyExpanded == "http.auth.user.id" { + repl.Set(keyExpanded, v) + } } return next.ServeHTTP(w, r) }