Commit 6aa0e30a authored by Matthew Holt's avatar Matthew Holt

basicauth: Don't remove Authorization header on good auth (fixes #1508)

parent 5a41e8bc
...@@ -62,13 +62,8 @@ func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error ...@@ -62,13 +62,8 @@ func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// by this point, authentication was successful // by this point, authentication was successful
isAuthenticated = true isAuthenticated = true
// remove credentials from request to avoid leaking upstream // let upstream middleware (e.g. fastcgi and cgi) know about authenticated user
r.Header.Del("Authorization") r = r.WithContext(context.WithValue(r.Context(), caddy.CtxKey("remote_user"), username))
// 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))
} }
} }
......
...@@ -92,8 +92,9 @@ func TestBasicAuth(t *testing.T) { ...@@ -92,8 +92,9 @@ func TestBasicAuth(t *testing.T) {
t.Errorf("Test %d: response should have a 'Www-Authenticate' header", i) t.Errorf("Test %d: response should have a 'Www-Authenticate' header", i)
} }
} else { } else {
if got, want := req.Header.Get("Authorization"), ""; got != want { if req.Header.Get("Authorization") == "" {
t.Errorf("Test %d: Expected Authorization header to be stripped from request after successful authentication, but is: %s", i, got) // 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)
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment