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/06/14 05:04:16 UTC

(incubator-devlake) branch dev0614-2 created (now ecf5d6fe3)

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

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


      at ecf5d6fe3 fix(framework): sanitize gitextractor plugin options correctly

This branch includes the following new commits:

     new ecf5d6fe3 fix(framework): sanitize gitextractor plugin options correctly

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(framework): sanitize gitextractor plugin options correctly

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

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

commit ecf5d6fe3b3bc5e00659dc1eba2c8fe70fe1b3fe
Author: d4x1 <15...@qq.com>
AuthorDate: Fri Jun 14 13:04:03 2024 +0800

    fix(framework): sanitize gitextractor plugin options correctly
---
 backend/server/services/pipeline.go | 14 ++++++++++++--
 backend/server/services/project.go  |  3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/backend/server/services/pipeline.go b/backend/server/services/pipeline.go
index 733b78f77..15d930205 100644
--- a/backend/server/services/pipeline.go
+++ b/backend/server/services/pipeline.go
@@ -47,10 +47,19 @@ var pluginOptionSanitizers = map[string]func(map[string]interface{}){
 	"gitextractor": func(options map[string]interface{}) {
 		if v, ok := options["url"]; ok {
 			gitUrl := cast.ToString(v)
-			u, _ := url.Parse(gitUrl)
+			u, err := url.Parse(gitUrl)
+			if err != nil {
+				logger.Error(err, "failed to parse git url", gitUrl)
+			}
 			if u != nil && u.User != nil {
 				password, ok := u.User.Password()
 				if ok {
+					escapedUrl, err := url.QueryUnescape(gitUrl)
+					if err != nil {
+						logger.Warn(err, "failed to unescape url %s", gitUrl)
+					} else {
+						gitUrl = escapedUrl
+					}
 					gitUrl = strings.Replace(gitUrl, password, strings.Repeat("*", len(password)), -1)
 					options["url"] = gitUrl
 				}
@@ -148,7 +157,8 @@ func SanitizeBlueprint(blueprint *models.Blueprint) error {
 func SanitizePipeline(pipeline *models.Pipeline) error {
 	for planStageIdx, pipelineStage := range pipeline.Plan {
 		for planTaskIdx := range pipelineStage {
-			pipelineTask, err := SanitizeTask(pipeline.Plan[planStageIdx][planTaskIdx])
+			task := pipeline.Plan[planStageIdx][planTaskIdx]
+			pipelineTask, err := SanitizeTask(task)
 			if err != nil {
 				return err
 			}
diff --git a/backend/server/services/project.go b/backend/server/services/project.go
index 547616d07..6b54d46fd 100644
--- a/backend/server/services/project.go
+++ b/backend/server/services/project.go
@@ -416,6 +416,9 @@ func makeProjectOutput(project *models.Project, withLastPipeline bool) (*models.
 	if err != nil {
 		return nil, errors.Default.Wrap(err, "Error to get blueprint by project")
 	}
+	if err := SanitizeBlueprint(projectOutput.Blueprint); err != nil {
+		return nil, errors.Convert(err)
+	}
 	if withLastPipeline {
 		if projectOutput.Blueprint == nil {
 			logger.Warn(fmt.Errorf("blueprint is nil"), "want to get latest pipeline, but blueprint is nil")