fix(34): WR-03 refuse user info in https git URLs
validateGitURL refused only a password, but GitHub, GitLab and Gitea take a token as the user part of an https URL. Such a URL was printed and written to .gitmodules by git submodule add, and so committed with the application. An https URL with any user info is now refused with a hint to use a credential helper; the user of an ssh URL stays allowed.
This commit is contained in:
@@ -78,7 +78,8 @@ func isGitURL(arg string) bool {
|
||||
// validateGitURL accepts https://, ssh:// and scp-like user@host:path
|
||||
// addresses (file:// only when cliGitProtocols allows it, in tests). It
|
||||
// refuses a leading "-", transport::address forms, http, credentials in
|
||||
// the URL and control characters.
|
||||
// the URL (any user info in an https URL, a password in any URL) and
|
||||
// control characters.
|
||||
func validateGitURL(raw string) error {
|
||||
switch {
|
||||
case raw == "":
|
||||
@@ -117,6 +118,12 @@ func validateGitURL(raw string) error {
|
||||
if _, hasPassword := u.User.Password(); hasPassword {
|
||||
return fmt.Errorf("git URL must not carry a password; use a git credential helper")
|
||||
}
|
||||
// GitHub, GitLab and Gitea take a token as the user part of an https
|
||||
// URL; it would be printed and written to .gitmodules (WR-03). The
|
||||
// user of an ssh URL is not a secret.
|
||||
if scheme == "https" && u.User != nil {
|
||||
return fmt.Errorf("an https git URL must not carry user info (a token in the user part ends up in .gitmodules); use a git credential helper")
|
||||
}
|
||||
if strings.HasPrefix(u.Path, "/-") || u.Path == "" || u.Path == "/" {
|
||||
return fmt.Errorf("git URL %q has an invalid path", raw)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user