Sfoglia il codice sorgente

add regex search of username and password in urls, which are replaced by strings.Replace

Mitja Zivkovic 7 anni fa
parent
commit
5669596518
1 ha cambiato i file con 9 aggiunte e 0 eliminazioni
  1. 9 0
      pkg/api/admin.go

+ 9 - 0
pkg/api/admin.go

@@ -1,6 +1,7 @@
 package api
 
 import (
+	"regexp"
 	"strings"
 
 	"github.com/grafana/grafana/pkg/bus"
@@ -21,6 +22,14 @@ func AdminGetSettings(c *m.ReqContext) {
 			if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") || (strings.Contains(keyName, "provider_config")) {
 				value = "************"
 			}
+			if strings.Contains(keyName, "url") {
+				var rgx = regexp.MustCompile(`.*:\/\/([^:]*):([^@]*)@.*?$`)
+				var subs = rgx.FindAllSubmatch([]byte(value), -1)
+				if subs != nil && len(subs[0]) == 3 {
+					value = strings.Replace(value, string(subs[0][1]), "******", 1)
+					value = strings.Replace(value, string(subs[0][2]), "******", 1)
+				}
+			}
 
 			jsonSec[keyName] = value
 		}