Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide sensitive content on admin panel progress monitor #19218

Merged
merged 9 commits into from
Mar 27, 2022
17 changes: 16 additions & 1 deletion modules/git/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/util"
)

var (
Expand Down Expand Up @@ -140,7 +141,21 @@ func (c *Command) RunWithContext(rc *RunContext) error {

desc := c.desc
if desc == "" {
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(c.args, " "), rc.Dir)
args := c.args
var argSensitiveURLIndexes []int
for i, arg := range c.args {
if strings.Index(arg, "://") != -1 && strings.IndexByte(arg, '@') != -1 {
argSensitiveURLIndexes = append(argSensitiveURLIndexes, i)
}
}
if len(argSensitiveURLIndexes) > 0 {
args = make([]string, len(c.args))
copy(args, c.args)
for _, urlArgIndex := range argSensitiveURLIndexes {
args[urlArgIndex] = util.NewStringURLSanitizer(args[urlArgIndex], true).Replace(args[urlArgIndex])
}
}
desc = fmt.Sprintf("%s %s [repo_path: %s]", c.name, strings.Join(args, " "), rc.Dir)
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
}

ctx, cancel, finished := process.GetManager().AddContextTimeout(c.parentContext, rc.Timeout, desc)
Expand Down
6 changes: 5 additions & 1 deletion modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"code.gitea.io/gitea/modules/proxy"
"code.gitea.io/gitea/modules/util"
)

// GPGSettings represents the default GPG settings for this repository
Expand Down Expand Up @@ -152,7 +153,8 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
if len(opts.Branch) > 0 {
cmd.AddArguments("-b", opts.Branch)
}
cmd.AddArguments("--", from, to)
cmd.AddArguments("--", from, to).
SetDescription(fmt.Sprintf("clone from %s to %s", util.NewStringURLSanitizer(from, true).Replace(from), to))
zeripath marked this conversation as resolved.
Show resolved Hide resolved

if opts.Timeout <= 0 {
opts.Timeout = -1
Expand Down Expand Up @@ -201,6 +203,8 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
if len(opts.Branch) > 0 {
cmd.AddArguments(opts.Branch)
}
cmd.SetDescription(fmt.Sprintf("push %s to %s", repoPath, util.NewStringURLSanitizer(opts.Remote, true).Replace(opts.Remote)))

zeripath marked this conversation as resolved.
Show resolved Hide resolved
var outbuf, errbuf strings.Builder

if opts.Timeout == 0 {
Expand Down
8 changes: 6 additions & 2 deletions services/mirror/mirror_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
return err
}

_, err = git.NewCommand(ctx, "remote", "add", remoteName, "--mirror=fetch", addr).RunInDir(repoPath)
cmd := git.NewCommand(ctx, "remote", "add", remoteName, "--mirror=fetch", addr)
cmd.SetDescription(fmt.Sprintf("add fetch remote %s to %s", util.NewStringURLSanitizer(addr, true).Replace(addr), repoPath))
zeripath marked this conversation as resolved.
Show resolved Hide resolved
_, err = cmd.RunInDir(repoPath)
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
return err
}
Expand All @@ -52,7 +54,9 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
return err
}

_, err = git.NewCommand(ctx, "remote", "add", remoteName, "--mirror=fetch", wikiRemotePath).RunInDir(wikiPath)
cmd = git.NewCommand(ctx, "remote", "add", remoteName, "--mirror=fetch", wikiRemotePath)
cmd.SetDescription(fmt.Sprintf("add fetch remote %s to %s", util.NewStringURLSanitizer(wikiRemotePath, true).Replace(wikiRemotePath), wikiPath))
zeripath marked this conversation as resolved.
Show resolved Hide resolved
_, err = cmd.RunInDir(wikiPath)
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion services/mirror/mirror_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ var stripExitStatus = regexp.MustCompile(`exit status \d+ - `)
// AddPushMirrorRemote registers the push mirror remote.
func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error {
addRemoteAndConfig := func(addr, path string) error {
if _, err := git.NewCommand(ctx, "remote", "add", "--mirror=push", m.RemoteName, addr).RunInDir(path); err != nil {
cmd := git.NewCommand(ctx, "remote", "add", "--mirror=push", m.RemoteName, addr)
cmd.SetDescription(fmt.Sprintf("add push remote %s to %s", util.NewStringURLSanitizer(addr, true).Replace(addr), path))
zeripath marked this conversation as resolved.
Show resolved Hide resolved
if _, err := cmd.RunInDir(path); err != nil {
return err
}
if _, err := git.NewCommand(ctx, "config", "--add", "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*").RunInDir(path); err != nil {
Expand Down