diff --git a/caddyhttp/basicauth/basicauth.go b/caddyhttp/basicauth/basicauth.go index 78a9192e2..49c0cb14f 100644 --- a/caddyhttp/basicauth/basicauth.go +++ b/caddyhttp/basicauth/basicauth.go @@ -62,13 +62,8 @@ func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error // by this point, authentication was successful isAuthenticated = true - // remove credentials from request to avoid leaking upstream - r.Header.Del("Authorization") - - // let upstream middleware (e.g. fastcgi and cgi) know about authenticated - // user; this replaces the request with a wrapped instance - r = r.WithContext(context.WithValue(r.Context(), - caddy.CtxKey("remote_user"), username)) + // let upstream middleware (e.g. fastcgi and cgi) know about authenticated user + r = r.WithContext(context.WithValue(r.Context(), caddy.CtxKey("remote_user"), username)) } } diff --git a/caddyhttp/basicauth/basicauth_test.go b/caddyhttp/basicauth/basicauth_test.go index 15003866e..18c79aec2 100644 --- a/caddyhttp/basicauth/basicauth_test.go +++ b/caddyhttp/basicauth/basicauth_test.go @@ -92,8 +92,9 @@ func TestBasicAuth(t *testing.T) { t.Errorf("Test %d: response should have a 'Www-Authenticate' header", i) } } else { - if got, want := req.Header.Get("Authorization"), ""; got != want { - t.Errorf("Test %d: Expected Authorization header to be stripped from request after successful authentication, but is: %s", i, got) + if req.Header.Get("Authorization") == "" { + // see issue #1508: https://github.com/mholt/caddy/issues/1508 + t.Errorf("Test %d: Expected Authorization header to be retained after successful auth, but was empty", i) } } }