Skip to content

Commit

Permalink
initial user-agent driven interstitial implementation (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jul 31, 2024
1 parent ed09ab2 commit 1f08ca4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
12 changes: 8 additions & 4 deletions endpoints/publicProxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ type Config struct {
Identity string
Address string
HostMatch string
Interstitial bool
Interstitial *InterstitialConfig
Oauth *OauthConfig
Tls *endpoints.TlsConfig
}

type InterstitialConfig struct {
Enabled bool
UserAgentPrefixes []string
}

type OauthConfig struct {
BindAddress string
RedirectUrl string
Expand All @@ -46,9 +51,8 @@ type OauthProviderConfig struct {

func DefaultConfig() *Config {
return &Config{
Identity: "public",
Address: "0.0.0.0:8080",
Interstitial: false,
Identity: "public",
Address: "0.0.0.0:8080",
}
}

Expand Down
34 changes: 25 additions & 9 deletions endpoints/publicProxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,31 @@ func shareHandler(handler http.Handler, pcfg *Config, key []byte, ctx ziti.Conte
if shrToken != "" {
if svc, found := endpoints.GetRefreshedService(shrToken, ctx); found {
if cfg, found := svc.Config[sdk.ZrokProxyConfig]; found {
if pcfg.Interstitial {
if v, istlFound := cfg["interstitial"]; istlFound {
if istlEnabled, ok := v.(bool); ok && istlEnabled {
skip := r.Header.Get("skip_zrok_interstitial")
_, zrokOkErr := r.Cookie("zrok_interstitial")
if skip == "" && zrokOkErr != nil {
logrus.Debugf("forcing interstitial for '%v'", r.URL)
interstitialUi.WriteInterstitialAnnounce(w)
return
if pcfg.Interstitial != nil && pcfg.Interstitial.Enabled {
sendInterstitial := true
if len(pcfg.Interstitial.UserAgentPrefixes) > 0 {
ua := r.Header.Get("User-Agent")
matched := false
for _, prefix := range pcfg.Interstitial.UserAgentPrefixes {
if strings.HasPrefix(ua, prefix) {
matched = true
break
}
}
if !matched {
sendInterstitial = false
}
}
if sendInterstitial {
if v, istlFound := cfg["interstitial"]; istlFound {
if istlEnabled, ok := v.(bool); ok && istlEnabled {
skip := r.Header.Get("skip_zrok_interstitial")
_, zrokOkErr := r.Cookie("zrok_interstitial")
if skip == "" && zrokOkErr != nil {
logrus.Debugf("forcing interstitial for '%v'", r.URL)
interstitialUi.WriteInterstitialAnnounce(w)
return
}
}
}
}
Expand Down

0 comments on commit 1f08ca4

Please sign in to comment.