@@ -87,7 +87,6 @@ type HeadlampConfig struct {
87
87
baseURL string
88
88
oidcScopes []string
89
89
proxyURLs []string
90
- compiledProxyURLs []glob.Glob
91
90
cache cache.Cache [interface {}]
92
91
kubeConfigStore kubeconfig.ContextStore
93
92
multiplexer * Multiplexer
@@ -622,7 +621,7 @@ func createExternalProxyHandler(config *HeadlampConfig) http.HandlerFunc {
622
621
return
623
622
}
624
623
625
- if ! config . isURLAllowed (url .String ()) {
624
+ if ! isURLAllowed (config . proxyURLs , url .String ()) {
626
625
logger .Log (logger .LevelError , nil , err , "no allowed proxy url match, request denied" )
627
626
http .Error (w , "no allowed proxy url match, request denied " , http .StatusBadRequest )
628
627
@@ -642,8 +641,9 @@ func getProxyURL(r *http.Request) string {
642
641
return proxyURL
643
642
}
644
643
645
- func (c * HeadlampConfig ) isURLAllowed (targetURL string ) bool {
646
- for _ , g := range c .compiledProxyURLs {
644
+ func isURLAllowed (proxyURLs []string , targetURL string ) bool {
645
+ for _ , proxyURL := range proxyURLs {
646
+ g := glob .MustCompile (proxyURL )
647
647
if g .Match (targetURL ) {
648
648
return true
649
649
}
@@ -899,30 +899,6 @@ func buildOIDCRedirectURL(config *HeadlampConfig, cluster, token string) string
899
899
return redirectURL + fmt .Sprintf ("auth?cluster=%s&token=%s" , cluster , token )
900
900
}
901
901
902
- func (c * HeadlampConfig ) compileProxyURLs () error {
903
- if len (c .proxyURLs ) == 0 {
904
- return nil
905
- }
906
-
907
- c .compiledProxyURLs = make ([]glob.Glob , 0 , len (c .proxyURLs ))
908
- for _ , pattern := range c .proxyURLs {
909
- pattern = strings .TrimSpace (pattern )
910
-
911
- if pattern == "" {
912
- continue
913
- }
914
-
915
- g , err := glob .Compile (pattern )
916
- if err != nil {
917
- return fmt .Errorf ("invalid proxy URL pattern %q: %w" , pattern , err )
918
- }
919
-
920
- c .compiledProxyURLs = append (c .compiledProxyURLs , g )
921
- }
922
-
923
- return nil
924
- }
925
-
926
902
func parseClusterAndToken (r * http.Request ) (string , string ) {
927
903
cluster := ""
928
904
re := regexp .MustCompile (`^/clusters/([^/]+)/.*` )
0 commit comments