Skip to content

Commit 0222623

Browse files
michaelkuhnlafriks
authored andcommitted
Explicitly disable Git credential helper (#5367)
* Explicitly disable Git credential helper If the user running Gitea has configured a credential helper, Git credentials might leak out of Gitea. There are two problems with credential helpers when combined with Gitea: 1. Credentials entered by a user when doing a migration or setting up a mirror will end up in the credential store. In the worst case, this is the plain text file ~/.git-credentials. 2. Credentials in the credential store will be used for migrations and mirrors by all users. For example, if user A sets up a mirror, their credentials will be stored. If user B later sets up a mirror from the same host and does not enter any credentials, user A's credentials will be used. This PR prepends -c credential.helper= to all Git commands to clear the list of helpers. This requires at least Git version 2.9, as previous versions will try to load an empty helper instead. For more details, see git/git@2432137 * Update git module
1 parent 08bf443 commit 0222623

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/setting/setting.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
_ "github.com/go-macaron/session/redis" // redis plugin for store session
3535
"github.com/go-xorm/core"
3636
"github.com/kballard/go-shellquote"
37+
"github.com/mcuadros/go-version"
3738
"gopkg.in/ini.v1"
3839
"strk.kbt.io/projects/go/libravatar"
3940
)
@@ -929,23 +930,7 @@ func NewContext() {
929930
log.Fatal(4, "Error retrieving git version: %v", err)
930931
}
931932

932-
splitVersion := strings.SplitN(binVersion, ".", 4)
933-
934-
majorVersion, err := strconv.ParseUint(splitVersion[0], 10, 64)
935-
if err != nil {
936-
log.Fatal(4, "Error parsing git major version: %v", err)
937-
}
938-
minorVersion, err := strconv.ParseUint(splitVersion[1], 10, 64)
939-
if err != nil {
940-
log.Fatal(4, "Error parsing git minor version: %v", err)
941-
}
942-
revisionVersion, err := strconv.ParseUint(splitVersion[2], 10, 64)
943-
if err != nil {
944-
log.Fatal(4, "Error parsing git revision version: %v", err)
945-
}
946-
947-
if !((majorVersion > 2) || (majorVersion == 2 && minorVersion > 1) ||
948-
(majorVersion == 2 && minorVersion == 1 && revisionVersion >= 2)) {
933+
if !version.Compare(binVersion, "2.1.2", ">=") {
949934

950935
LFS.StartServer = false
951936
log.Error(4, "LFS server support needs at least Git v2.1.2")
@@ -1206,6 +1191,16 @@ func NewContext() {
12061191
sec = Cfg.Section("U2F")
12071192
U2F.TrustedFacets, _ = shellquote.Split(sec.Key("TRUSTED_FACETS").MustString(strings.TrimRight(AppURL, "/")))
12081193
U2F.AppID = sec.Key("APP_ID").MustString(strings.TrimRight(AppURL, "/"))
1194+
1195+
binVersion, err := git.BinVersion()
1196+
if err != nil {
1197+
log.Fatal(4, "Error retrieving git version: %v", err)
1198+
}
1199+
1200+
if version.Compare(binVersion, "2.9", ">=") {
1201+
// Explicitly disable credential helper, otherwise Git credentials might leak
1202+
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
1203+
}
12091204
}
12101205

12111206
// Service settings

vendor/code.gitea.io/git/command.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/git/repo_tree.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/git/tree.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/code.gitea.io/git/tree_entry.go

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)