-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24ab49f
commit af162fe
Showing
2 changed files
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,11 @@ 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 the URL is usually ssh://[email protected]. | ||
// The username is required to tell the server you're doing Git operations, but not needed for HTTPS. | ||
if _, isSet := u.User.Password(); !isSet { | ||
u.User = nil | ||
} | ||
return u.String() | ||
} | ||
if scpUrl.MatchString(argument) { | ||
|
@@ -109,7 +114,12 @@ func Scrub(argument string) string { | |
// host changed, possible attack | ||
return argument | ||
} | ||
return newUrl | ||
// Clear the user if there is no password, since the URL is usually [email protected]. | ||
// The username is required to tell the server you're doing Git operations, but not needed for HTTPS. | ||
if _, isSet := u.User.Password(); !isSet { | ||
u.User = nil | ||
} | ||
return u.String() | ||
} | ||
return argument | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|