Skip to content

Commit

Permalink
providers/proxy: fix Issuer when AUTHENTIK_HOST_BROWSER is set (#11968)
Browse files Browse the repository at this point in the history
correctly use host_browser's hostname as host header for token requests to ensure Issuer is identical
  • Loading branch information
BeryJu authored Nov 12, 2024
1 parent 1f6ae73 commit a892d4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion internal/outpost/proxyv2/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"goauthentik.io/api/v3"
"goauthentik.io/internal/config"
"goauthentik.io/internal/outpost/ak"
"goauthentik.io/internal/outpost/proxyv2/constants"
"goauthentik.io/internal/outpost/proxyv2/hs256"
Expand Down Expand Up @@ -121,6 +122,14 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, server Server, old
bs := string(h.Sum([]byte(*p.ClientId)))
sessionName := fmt.Sprintf("authentik_proxy_%s", bs[:8])

// When HOST_BROWSER is set, use that as Host header for token requests to make the issuer match
// otherwise we use the internally configured authentik_host
tokenEndpointHost := server.API().Outpost.Config["authentik_host"].(string)
if config.Get().AuthentikHostBrowser != "" {
tokenEndpointHost = config.Get().AuthentikHostBrowser
}
publicHTTPClient := web.NewHostInterceptor(c, tokenEndpointHost)

a := &Application{
Host: externalHost.Host,
log: muxLogger,
Expand All @@ -131,7 +140,7 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, server Server, old
tokenVerifier: verifier,
proxyConfig: p,
httpClient: c,
publicHostHTTPClient: web.NewHostInterceptor(c, server.API().Outpost.Config["authentik_host"].(string)),
publicHostHTTPClient: publicHTTPClient,
mux: mux,
errorTemplates: templates.GetTemplates(),
ak: server.API(),
Expand Down
6 changes: 4 additions & 2 deletions internal/utils/web/http_host_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ type hostInterceptor struct {
}

func (t hostInterceptor) RoundTrip(r *http.Request) (*http.Response, error) {
r.Host = t.host
r.Header.Set("X-Forwarded-Proto", t.scheme)
if r.Host != t.host {
r.Host = t.host
r.Header.Set("X-Forwarded-Proto", t.scheme)
}
return t.inner.RoundTrip(r)
}

Expand Down

0 comments on commit a892d4a

Please sign in to comment.