move set request headers before handle allow public access to fix https://github.com/pomerium/pomerium/issues/477 (#479)

This commit is contained in:
ohdarling88 2020-02-03 03:15:13 +08:00 committed by GitHub
parent 50754bed31
commit 111aa8f4d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,6 +259,12 @@ func (p *Proxy) reverseProxyHandler(r *mux.Router, policy config.Policy) (*mux.R
rp.Use(middleware.CorsBypass(proxy))
}
// Optional: if additional headers are to be set for this url
if len(policy.SetRequestHeaders) != 0 {
log.Warn().Interface("headers", policy.SetRequestHeaders).Msg("proxy: set request headers")
rp.Use(SetResponseHeaders(policy.SetRequestHeaders))
}
// Optional: if a public route, skip access control middleware
if policy.AllowPublicUnauthenticatedAccess {
log.Warn().Str("route", policy.String()).Msg("proxy: all access control disabled")
@ -281,11 +287,7 @@ func (p *Proxy) reverseProxyHandler(r *mux.Router, policy config.Policy) (*mux.R
}
rp.Use(p.SignRequest(signer))
}
// Optional: if additional headers are to be set for this url
if len(policy.SetRequestHeaders) != 0 {
log.Warn().Interface("headers", policy.SetRequestHeaders).Msg("proxy: set request headers")
rp.Use(SetResponseHeaders(policy.SetRequestHeaders))
}
return r, nil
}