You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/07/19 09:41:44 UTC
(incubator-devlake) branch main updated: fix(gitextractor): sanitize git tokens (#7767)
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new d55b84cea fix(gitextractor): sanitize git tokens (#7767)
d55b84cea is described below
commit d55b84cea7dad26fdc5a5203e11bb330f0aaac5a
Author: Lynwee <15...@qq.com>
AuthorDate: Fri Jul 19 17:41:40 2024 +0800
fix(gitextractor): sanitize git tokens (#7767)
---
backend/plugins/gitextractor/parser/clone_gitcli.go | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/backend/plugins/gitextractor/parser/clone_gitcli.go b/backend/plugins/gitextractor/parser/clone_gitcli.go
index bd7e7a7ab..ce987eb54 100644
--- a/backend/plugins/gitextractor/parser/clone_gitcli.go
+++ b/backend/plugins/gitextractor/parser/clone_gitcli.go
@@ -235,7 +235,22 @@ func (g *GitcliCloner) execCommand(cmd *exec.Cmd) errors.Error {
strings.Contains(outputString, "fatal: the remote end hung up unexpectedly") {
return ErrNoData
}
- return errors.Default.New(fmt.Sprintf("git cmd %v in %s failed: %s", cmd.Args, cmd.Dir, outputString))
+ return errors.Default.New(fmt.Sprintf("git cmd %v in %s failed: %s", sanitizeArgs(cmd.Args), cmd.Dir, outputString))
}
return nil
}
+
+func sanitizeArgs(args []string) []string {
+ var ret []string
+ for _, arg := range args {
+ u, err := url.Parse(arg)
+ if err == nil && u != nil && u.User != nil {
+ password, ok := u.User.Password()
+ if ok {
+ arg = strings.Replace(arg, password, strings.Repeat("*", len(password)), -1)
+ }
+ }
+ ret = append(ret, arg)
+ }
+ return ret
+}