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:34:00 UTC

(incubator-devlake) branch dev-1 created (now e77753a64)

This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a change to branch dev-1
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


      at e77753a64 fix(gitextractor): sanitize git tokens

This branch includes the following new commits:

     new e77753a64 fix(gitextractor): sanitize git tokens

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-devlake) 01/01: fix(gitextractor): sanitize git tokens

Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch dev-1
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit e77753a6442d2308e45dcd67c76ef3ed25d500d4
Author: d4x1 <15...@qq.com>
AuthorDate: Fri Jul 19 17:33:52 2024 +0800

    fix(gitextractor): sanitize git tokens
---
 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
+}