Skip to content

Commit 29b9513

Browse files
Add support to hide password from validation URL (#351)
* Add support to hide password from validation URL * Update util/es_logger.go Co-authored-by: Siddharth Kothari <sids.aquarius@gmail.com>
1 parent f152788 commit 29b9513

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

plugins/querytranslate/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (r *QueryTranslate) validate() http.HandlerFunc {
366366
validateMapToShow = append(validateMapToShow, map[string]interface{}{
367367
"id": requestID,
368368
"endpoint": map[string]interface{}{
369-
"url": request.URL.String(),
369+
"url": util.CleanPasswordFromURL(request.URL.String()),
370370
"method": methodUsed,
371371
"headers": headersPassed,
372372
"body": bodyAsMap,

util/es_logger.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,23 @@ func cleanSenstiveData(vars *[]interface{}) {
5757
continue
5858
}
5959

60-
// Check if URL
61-
isURL, _ := regexp.MatchString(`^https?://(www.)?.+\..+$`, stringedVar)
62-
if !isURL {
63-
continue
64-
}
65-
66-
// If it is an URL, clean it up
67-
cleanerRe := regexp.MustCompile(`\/\/(?P<username>.+):.+@`)
68-
cleanedVar := cleanerRe.ReplaceAllString(stringedVar, "//${username}:***@")
60+
cleanedVar := CleanPasswordFromURL(stringedVar)
6961

7062
(*vars)[index] = cleanedVar
7163
}
7264
}
65+
66+
// CleanPasswordFromURL will clean password from the URL if
67+
// it is present
68+
func CleanPasswordFromURL(URL string) string {
69+
// Check if URL
70+
isURL, _ := regexp.MatchString(`^https?://(www.)?.+\..+$`, URL)
71+
if !isURL {
72+
return URL
73+
}
74+
75+
// If it is an URL, clean it up
76+
cleanerRe := regexp.MustCompile(`\/\/(?P<username>.+):.+@`)
77+
cleanedVar := cleanerRe.ReplaceAllString(URL, "//${username}:********@")
78+
return cleanedVar
79+
}

0 commit comments

Comments
 (0)