From 01cbb92b617adf35f1e87a134409ca4f0362dc51 Mon Sep 17 00:00:00 2001 From: huyz Date: Wed, 6 May 2026 20:55:36 -0500 Subject: [PATCH 1/2] URLcheck: redact password in UI --- modules/urlcheck/urlResult.go | 16 ++++++++++ modules/urlcheck/urlResult_test.go | 48 ++++++++++++++++++++++++++++++ modules/urlcheck/view.go | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/modules/urlcheck/urlResult.go b/modules/urlcheck/urlResult.go index ca8425cb9..5984c9897 100644 --- a/modules/urlcheck/urlResult.go +++ b/modules/urlcheck/urlResult.go @@ -14,6 +14,22 @@ type urlResult struct { IsValid bool } +// DisplayURL returns the URL with any Basic Auth password redacted. +func (ur urlResult) DisplayURL() string { + u, err := url.Parse(ur.Url) + if err != nil || u.User == nil { + return ur.Url + } + + username := u.User.Username() + if _, hasPassword := u.User.Password(); !hasPassword { + return ur.Url + } + + u.User = url.UserPassword(username, "xxxxx") + return u.String() +} + // Create a UrlResult instance from an urls occurence in the settings func newUrlResult(urlString string) *urlResult { diff --git a/modules/urlcheck/urlResult_test.go b/modules/urlcheck/urlResult_test.go index 975460a50..63d64938e 100644 --- a/modules/urlcheck/urlResult_test.go +++ b/modules/urlcheck/urlResult_test.go @@ -44,3 +44,51 @@ func Test_newUrlResult(t *testing.T) { }) } } + +func Test_urlResult_DisplayURL(t *testing.T) { + tests := []struct { + name string + url string + want string + }{ + { + name: "no_auth", + url: "https://example.com/path?var=1", + want: "https://example.com/path?var=1", + }, + { + name: "username_only", + url: "https://user@example.com/path", + want: "https://user@example.com/path", + }, + { + name: "username_and_password", + url: "https://user:secret@example.com/path", + want: "https://user:xxxxx@example.com/path", + }, + { + name: "username_and_empty_password", + url: "https://user:@example.com/path", + want: "https://user:xxxxx@example.com/path", + }, + { + name: "encoded_credentials", + url: "https://user%40example.com:s%40cret@example.com/path", + want: "https://user%40example.com:xxxxx@example.com/path", + }, + { + name: "invalid_url", + url: "http://not\nurl.com?var=1", + want: "http://not\nurl.com?var=1", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := urlResult{Url: tt.url} + + assert.Equal(t, tt.want, got.DisplayURL()) + assert.Equal(t, tt.url, got.Url) + }) + } +} diff --git a/modules/urlcheck/view.go b/modules/urlcheck/view.go index 4d96145d6..3110ddb69 100644 --- a/modules/urlcheck/view.go +++ b/modules/urlcheck/view.go @@ -16,7 +16,7 @@ func (widget *Widget) PrepareTemplate() { widget.templateString = "{{range .}} " + "{{. | getResultColor}}" + "[{{if eq .ResultCode 999}}---{{else}}{{.ResultCode}}{{end}}]" + - textColor + "{{.Url}}" + + textColor + "{{.DisplayURL}}" + labelColor + "{{.ResultMessage}}" + "\n{{end}}" From 6385d37d1d7939e93e4f588c4ea197af103f6665 Mon Sep 17 00:00:00 2001 From: huyz Date: Wed, 6 May 2026 22:23:37 -0500 Subject: [PATCH 2/2] URLcheck: rename DisplayURL to DisplayUrl for consistency --- modules/urlcheck/urlResult.go | 4 ++-- modules/urlcheck/urlResult_test.go | 4 ++-- modules/urlcheck/view.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/urlcheck/urlResult.go b/modules/urlcheck/urlResult.go index 5984c9897..c1b95b74a 100644 --- a/modules/urlcheck/urlResult.go +++ b/modules/urlcheck/urlResult.go @@ -14,8 +14,8 @@ type urlResult struct { IsValid bool } -// DisplayURL returns the URL with any Basic Auth password redacted. -func (ur urlResult) DisplayURL() string { +// DisplayUrl returns the URL with any Basic Auth password redacted. +func (ur urlResult) DisplayUrl() string { u, err := url.Parse(ur.Url) if err != nil || u.User == nil { return ur.Url diff --git a/modules/urlcheck/urlResult_test.go b/modules/urlcheck/urlResult_test.go index 63d64938e..1b3ee942d 100644 --- a/modules/urlcheck/urlResult_test.go +++ b/modules/urlcheck/urlResult_test.go @@ -45,7 +45,7 @@ func Test_newUrlResult(t *testing.T) { } } -func Test_urlResult_DisplayURL(t *testing.T) { +func Test_urlResult_DisplayUrl(t *testing.T) { tests := []struct { name string url string @@ -87,7 +87,7 @@ func Test_urlResult_DisplayURL(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got := urlResult{Url: tt.url} - assert.Equal(t, tt.want, got.DisplayURL()) + assert.Equal(t, tt.want, got.DisplayUrl()) assert.Equal(t, tt.url, got.Url) }) } diff --git a/modules/urlcheck/view.go b/modules/urlcheck/view.go index 3110ddb69..2b93d8f19 100644 --- a/modules/urlcheck/view.go +++ b/modules/urlcheck/view.go @@ -16,7 +16,7 @@ func (widget *Widget) PrepareTemplate() { widget.templateString = "{{range .}} " + "{{. | getResultColor}}" + "[{{if eq .ResultCode 999}}---{{else}}{{.ResultCode}}{{end}}]" + - textColor + "{{.DisplayURL}}" + + textColor + "{{.DisplayUrl}}" + labelColor + "{{.ResultMessage}}" + "\n{{end}}"