Skip to content

Commit 44f3dea

Browse files
authored
fix(framework): sanitize gitextractor plugin options correctly (#7622)
* fix(framework): sanitize gitextractor plugin options correctly * fix(test): fix panic when running CI
1 parent 63e0ce6 commit 44f3dea

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

backend/server/services/pipeline.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ var pluginOptionSanitizers = map[string]func(map[string]interface{}){
4747
"gitextractor": func(options map[string]interface{}) {
4848
if v, ok := options["url"]; ok {
4949
gitUrl := cast.ToString(v)
50-
u, _ := url.Parse(gitUrl)
50+
u, err := url.Parse(gitUrl)
51+
if err != nil {
52+
logger.Error(err, "failed to parse git url", gitUrl)
53+
}
5154
if u != nil && u.User != nil {
5255
password, ok := u.User.Password()
5356
if ok {
57+
escapedUrl, err := url.QueryUnescape(gitUrl)
58+
if err != nil {
59+
logger.Warn(err, "failed to unescape url %s", gitUrl)
60+
} else {
61+
gitUrl = escapedUrl
62+
}
5463
gitUrl = strings.Replace(gitUrl, password, strings.Repeat("*", len(password)), -1)
5564
options["url"] = gitUrl
5665
}
@@ -148,7 +157,8 @@ func SanitizeBlueprint(blueprint *models.Blueprint) error {
148157
func SanitizePipeline(pipeline *models.Pipeline) error {
149158
for planStageIdx, pipelineStage := range pipeline.Plan {
150159
for planTaskIdx := range pipelineStage {
151-
pipelineTask, err := SanitizeTask(pipeline.Plan[planStageIdx][planTaskIdx])
160+
task := pipeline.Plan[planStageIdx][planTaskIdx]
161+
pipelineTask, err := SanitizeTask(task)
152162
if err != nil {
153163
return err
154164
}

backend/server/services/project.go

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ func makeProjectOutput(project *models.Project, withLastPipeline bool) (*models.
416416
if err != nil {
417417
return nil, errors.Default.Wrap(err, "Error to get blueprint by project")
418418
}
419+
if projectOutput.Blueprint != nil {
420+
if err := SanitizeBlueprint(projectOutput.Blueprint); err != nil {
421+
return nil, errors.Convert(err)
422+
}
423+
}
419424
if withLastPipeline {
420425
if projectOutput.Blueprint == nil {
421426
logger.Warn(fmt.Errorf("blueprint is nil"), "want to get latest pipeline, but blueprint is nil")

0 commit comments

Comments
 (0)