From 78045b514f3f7df7226ecb9f8bd659d3762e8cf0 Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Wed, 21 May 2025 19:08:32 +0530 Subject: [PATCH 1/2] fix: add safety checks to prevent index-out-of-range panics in CdHandler --- pkg/pipeline/CdHandler.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/pipeline/CdHandler.go b/pkg/pipeline/CdHandler.go index 4fbdba573d..9c05acf21e 100644 --- a/pkg/pipeline/CdHandler.go +++ b/pkg/pipeline/CdHandler.go @@ -735,7 +735,13 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerViewForEnvironment(re // filter out pipelines for unauthorized apps but not envs appResults, _ := request.CheckAuthBatch(token, appObjectArr, envObjectArr) for _, pipeline := range pipelines { - appObject := objects[pipeline.Id][0] + // Safety check to prevent index-out-of-range panic + objectArr, ok := objects[pipeline.Id] + if !ok { + impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id) + continue + } + appObject := objectArr[0] if !(appResults[appObject]) { // if user unauthorized, skip items continue @@ -872,13 +878,24 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou objects := impl.enforcerUtil.GetAppAndEnvObjectByPipelineIds(pipelineIds) pipelineIds = []int{} for _, object := range objects { - appObjectArr = append(appObjectArr, object[0]) - envObjectArr = append(envObjectArr, object[1]) + // Safety check to prevent index out of range panic + if len(object) >= 2 { + appObjectArr = append(appObjectArr, object[0]) + envObjectArr = append(envObjectArr, object[1]) + } else { + impl.Logger.Warnw("skipping object with insufficient elements", "object", object) + } } appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr) for _, pipeline := range cdPipelines { - appObject := objects[pipeline.Id][0] - envObject := objects[pipeline.Id][1] + // Safety check to prevent index out of range panic + objectArr, ok := objects[pipeline.Id] + if !ok || len(objectArr) < 2 { + impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id) + continue + } + appObject := objectArr[0] + envObject := objectArr[1] if !(appResults[appObject] && envResults[envObject]) { // if user unauthorized, skip items continue From f31504a5e12809ab31347251db017078ab727fbd Mon Sep 17 00:00:00 2001 From: prakhar katiyar Date: Wed, 21 May 2025 19:30:56 +0530 Subject: [PATCH 2/2] fix: add safety checks to prevent index-out-of-range panics in CdHandler --- pkg/pipeline/CdHandler.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/pipeline/CdHandler.go b/pkg/pipeline/CdHandler.go index 9c05acf21e..e67869a734 100644 --- a/pkg/pipeline/CdHandler.go +++ b/pkg/pipeline/CdHandler.go @@ -878,24 +878,13 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou objects := impl.enforcerUtil.GetAppAndEnvObjectByPipelineIds(pipelineIds) pipelineIds = []int{} for _, object := range objects { - // Safety check to prevent index out of range panic - if len(object) >= 2 { - appObjectArr = append(appObjectArr, object[0]) - envObjectArr = append(envObjectArr, object[1]) - } else { - impl.Logger.Warnw("skipping object with insufficient elements", "object", object) - } + appObjectArr = append(appObjectArr, object[0]) + envObjectArr = append(envObjectArr, object[1]) } appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr) for _, pipeline := range cdPipelines { - // Safety check to prevent index out of range panic - objectArr, ok := objects[pipeline.Id] - if !ok || len(objectArr) < 2 { - impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id) - continue - } - appObject := objectArr[0] - envObject := objectArr[1] + appObject := objects[pipeline.Id][0] + envObject := objects[pipeline.Id][1] if !(appResults[appObject] && envResults[envObject]) { // if user unauthorized, skip items continue