diff --git a/internal/httputil/errors.go b/internal/httputil/errors.go index 8e21e76d4..47f6821ae 100644 --- a/internal/httputil/errors.go +++ b/internal/httputil/errors.go @@ -2,6 +2,7 @@ package httputil import ( "encoding/json" + "errors" "html/template" "net/http" @@ -11,6 +12,8 @@ import ( "github.com/pomerium/pomerium/internal/version" ) +var ErrRedirectOnly = errors.New("httputil: redirecting to authenticate service") + var errorTemplate = template.Must(frontend.NewTemplates()) var fullVersion = version.FullVersion() @@ -60,11 +63,14 @@ type errResponse struct { // It does not otherwise end the request; the caller should ensure no further // writes are done to w. func (e *HTTPError) ErrorResponse(w http.ResponseWriter, r *http.Request) { + log.FromRequest(r).Info().Err(e).Msg("httputil: ErrorResponse") + if errors.Is(e, ErrRedirectOnly) { + return + } // indicate to clients that the error originates from Pomerium, not the app w.Header().Set(HeaderPomeriumResponse, "true") w.WriteHeader(e.Status) - log.FromRequest(r).Info().Err(e).Msg("httputil: ErrorResponse") var requestID string if id, ok := log.IDFromRequest(r); ok { requestID = id diff --git a/proxy/middleware.go b/proxy/middleware.go index 73b3b883e..f644c6745 100644 --- a/proxy/middleware.go +++ b/proxy/middleware.go @@ -83,7 +83,7 @@ func (p *Proxy) redirectToSignin(w http.ResponseWriter, r *http.Request) error { log.FromRequest(r).Debug().Str("url", signinURL.String()).Msg("proxy: redirectToSignin") httputil.Redirect(w, r, urlutil.NewSignedURL(p.SharedKey, &signinURL).String(), http.StatusFound) p.sessionStore.ClearSession(w, r) - return nil + return httputil.ErrRedirectOnly } // AuthorizeSession is middleware to enforce a user is authorized for a request.