Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func Scrub(argument string) string {
u, err := url.ParseRequestURI(argument)
if err == nil && u.Host != "" && contains(allowedSchemes, u.Scheme) {
u.Scheme = "https"
// clear the user if there is no password, since it's common to use [email protected]
if _, isSet := u.User.Password(); !isSet {
u.User = nil
}
return u.String()
}
if scpUrl.MatchString(argument) {
Expand All @@ -109,7 +113,11 @@ func Scrub(argument string) string {
// host changed, possible attack
return argument
}
return newUrl
// clear the user if there is no password, since it's common to use [email protected]
if _, isSet := u.User.Password(); !isSet {
u.User = nil
}
return u.String()
}
return argument
}
Expand Down
8 changes: 6 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ func TestScrub(t *testing.T) {
},
{
input: "[email protected]:dependabot/git-https-shim",
expected: "https://[email protected]/dependabot/git-https-shim",
expected: "https://github.com/dependabot/git-https-shim",
},
{
input: "ssh://user:[email protected]/dependabot/git-https-shim",
expected: "https://user:[email protected]/dependabot/git-https-shim",
},
{
input: "ssh://[email protected]/dependabot/git-https-shim",
expected: "https://git@github.com/dependabot/git-https-shim",
expected: "https://github.com/dependabot/git-https-shim",
},
{
input: "ssh://github.com/dependabot/git-https-shim",
Expand Down