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
24321375cd
* Update git module
This commit is contained in:
parent
08bf443016
commit
0222623be9
6 changed files with 51 additions and 25 deletions
|
@ -34,6 +34,7 @@ import (
|
|||
_ "github.com/go-macaron/session/redis" // redis plugin for store session
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/kballard/go-shellquote"
|
||||
"github.com/mcuadros/go-version"
|
||||
"gopkg.in/ini.v1"
|
||||
"strk.kbt.io/projects/go/libravatar"
|
||||
)
|
||||
|
@ -929,23 +930,7 @@ func NewContext() {
|
|||
log.Fatal(4, "Error retrieving git version: %v", err)
|
||||
}
|
||||
|
||||
splitVersion := strings.SplitN(binVersion, ".", 4)
|
||||
|
||||
majorVersion, err := strconv.ParseUint(splitVersion[0], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Error parsing git major version: %v", err)
|
||||
}
|
||||
minorVersion, err := strconv.ParseUint(splitVersion[1], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Error parsing git minor version: %v", err)
|
||||
}
|
||||
revisionVersion, err := strconv.ParseUint(splitVersion[2], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Error parsing git revision version: %v", err)
|
||||
}
|
||||
|
||||
if !((majorVersion > 2) || (majorVersion == 2 && minorVersion > 1) ||
|
||||
(majorVersion == 2 && minorVersion == 1 && revisionVersion >= 2)) {
|
||||
if !version.Compare(binVersion, "2.1.2", ">=") {
|
||||
|
||||
LFS.StartServer = false
|
||||
log.Error(4, "LFS server support needs at least Git v2.1.2")
|
||||
|
@ -1206,6 +1191,16 @@ func NewContext() {
|
|||
sec = Cfg.Section("U2F")
|
||||
U2F.TrustedFacets, _ = shellquote.Split(sec.Key("TRUSTED_FACETS").MustString(strings.TrimRight(AppURL, "/")))
|
||||
U2F.AppID = sec.Key("APP_ID").MustString(strings.TrimRight(AppURL, "/"))
|
||||
|
||||
binVersion, err := git.BinVersion()
|
||||
if err != nil {
|
||||
log.Fatal(4, "Error retrieving git version: %v", err)
|
||||
}
|
||||
|
||||
if version.Compare(binVersion, "2.9", ">=") {
|
||||
// Explicitly disable credential helper, otherwise Git credentials might leak
|
||||
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
|
||||
}
|
||||
}
|
||||
|
||||
// Service settings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue