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

github-bot pushed a commit to branch release-v1.0-auto-cherry-pick-7622
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit bc458a9dd0259655c90c4667b2c4fa71a82d8d98
Author: Lynwee <[email protected]>
AuthorDate: Fri Jun 14 13:43:24 2024 +0800

    fix(framework): sanitize gitextractor plugin options correctly (#7622)
    
    * fix(framework): sanitize gitextractor plugin options correctly
    
    * fix(test): fix panic when running CI
---
 backend/server/services/pipeline.go | 14 ++++++++++++--
 backend/server/services/project.go  |  5 +++++
 2 files changed, 17 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..e119979ab 100644
--- a/backend/server/services/project.go
+++ b/backend/server/services/project.go
@@ -416,6 +416,11 @@ func makeProjectOutput(project *models.Project, 
withLastPipeline bool) (*models.
        if err != nil {
                return nil, errors.Default.Wrap(err, "Error to get blueprint by 
project")
        }
+       if projectOutput.Blueprint != nil {
+               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")

Reply via email to