Skip to content

Commit 7e8da0e

Browse files
[scrubber] Scrub URLs in log messages
1 parent e04327e commit 7e8da0e

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

components/scrubber/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ var (
3232
}
3333

3434
// HashedValues are regular expressions which - when matched - cause the entire value to be hashed
35-
HashedValues = map[string]*regexp.Regexp{}
35+
HashedValues = map[string]*regexp.Regexp{
36+
"url": regexp.MustCompile(`https?://[^\s]+`),
37+
}
3638

3739
// RedactedValues are regular expressions which - when matched - cause the entire value to be redacted
3840
RedactedValues = map[string]*regexp.Regexp{

components/scrubber/sanitisation_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestSanitiser(t *testing.T) {
2929
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS user repo", Input: "https://bitbucket.gitpod-dev.com/users/gitpod/repos/repotest/browse", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/users/[redacted:md5:5bc8d0354fba47db774b70d2a9161bbb]/repos/[redacted:md5:3c3f61c49fd93e84a73e33f6194586cd]/browse"},
3030
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS project PR", Input: "https://bitbucket.gitpod-dev.com/projects/TES/repos/2k-repos-0/pull-requests/1/overview", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/projects/[redacted:md5:08e789053de980e0f1ac70a61125a17d]/repos/[redacted:md5:14571b57e21a5c26b9e81fe6216e27d1]/pull-requests/1/[redacted:md5:bce059749d61c1c247c303d0118d0d53]"},
3131
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS branch", Input: "https://bitbucket.gitpod-dev.com/projects/TES/repos/2k-repos-0/branches?base=test", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/projects/[redacted:md5:08e789053de980e0f1ac70a61125a17d]/repos/[redacted:md5:14571b57e21a5c26b9e81fe6216e27d1]/branches?[redacted:md5:0135e6beb2a6deb4f0668facc47bce76]"},
32+
{Func: SanitiseHashURLPathSegments, Name: "GitLab Git URL", Input: "https://gitlab.com/acme-corp/web/frontend/services/deployment-manager.git", Expectation: "[redacted:md5:8c3e227c86409b1e3e734e711a77fd6c]/[redacted:md5:7c879ad6a7611d94b34c1911910257c9]/[redacted:md5:2567a5ec9705eb7ac2c984033e06189d]/[redacted:md5:aca33b9c046b2a50b8c3c54cc0380de8]/[redacted:md5:10cd395cf71c18328c863c08e78f3fd0]/[redacted:md5:d890bc8f5f32a034527f9be94624af58]"},
3233
}
3334

3435
for _, test := range tests {

components/scrubber/scrubber.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ func (s *scrubberImpl) scrubJsonSlice(val []interface{}) error {
449449
func (s *scrubberImpl) Value(value string) string {
450450
for key, expr := range s.HashedValues {
451451
value = expr.ReplaceAllStringFunc(value, func(s string) string {
452+
if key == "url" {
453+
return SanitiseHashURLPathSegments(s)
454+
}
452455
return SanitiseHash(s, SanitiseWithKeyName(key))
453456
})
454457
}

components/scrubber/scrubber_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func TestValue(t *testing.T) {
2222
{Name: "empty string"},
2323
{Name: "email", Value: "[email protected]", Expectation: "[redacted:email]"},
2424
{Name: "email in text", Value: "The email is [email protected] or [email protected]", Expectation: "The email is [redacted:email] or [redacted:email]"},
25+
{Name: "GitLab Git URL in text", Value: "Content initialization failed: cannot initialize workspace: git initializer gitClone: git clone --depth=1 --shallow-submodules https://gitlab.com/acme-corp/web/frontend/services/deployment-manager.git --config http.version=HTTP/1.1 . failed (exit status 128)", Expectation: "Content initialization failed: cannot initialize workspace: git initializer gitClone: git clone --depth=1 --shallow-submodules [redacted:md5:8c3e227c86409b1e3e734e711a77fd6c]/[redacted:md5:7c879ad6a7611d94b34c1911910257c9]/[redacted:md5:2567a5ec9705eb7ac2c984033e06189d]/[redacted:md5:aca33b9c046b2a50b8c3c54cc0380de8]/[redacted:md5:10cd395cf71c18328c863c08e78f3fd0]/[redacted:md5:d890bc8f5f32a034527f9be94624af58] --config http.version=HTTP/1.1 . failed (exit status 128)"},
2526
}
2627

2728
for _, test := range tests {

0 commit comments

Comments
 (0)