Skip to content

Commit 78045b5

Browse files
committed
fix: add safety checks to prevent index-out-of-range panics in CdHandler
1 parent 4648291 commit 78045b5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

pkg/pipeline/CdHandler.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,13 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerViewForEnvironment(re
735735
// filter out pipelines for unauthorized apps but not envs
736736
appResults, _ := request.CheckAuthBatch(token, appObjectArr, envObjectArr)
737737
for _, pipeline := range pipelines {
738-
appObject := objects[pipeline.Id][0]
738+
// Safety check to prevent index-out-of-range panic
739+
objectArr, ok := objects[pipeline.Id]
740+
if !ok {
741+
impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id)
742+
continue
743+
}
744+
appObject := objectArr[0]
739745
if !(appResults[appObject]) {
740746
// if user unauthorized, skip items
741747
continue
@@ -872,13 +878,24 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou
872878
objects := impl.enforcerUtil.GetAppAndEnvObjectByPipelineIds(pipelineIds)
873879
pipelineIds = []int{}
874880
for _, object := range objects {
875-
appObjectArr = append(appObjectArr, object[0])
876-
envObjectArr = append(envObjectArr, object[1])
881+
// Safety check to prevent index out of range panic
882+
if len(object) >= 2 {
883+
appObjectArr = append(appObjectArr, object[0])
884+
envObjectArr = append(envObjectArr, object[1])
885+
} else {
886+
impl.Logger.Warnw("skipping object with insufficient elements", "object", object)
887+
}
877888
}
878889
appResults, envResults := request.CheckAuthBatch(token, appObjectArr, envObjectArr)
879890
for _, pipeline := range cdPipelines {
880-
appObject := objects[pipeline.Id][0]
881-
envObject := objects[pipeline.Id][1]
891+
// Safety check to prevent index out of range panic
892+
objectArr, ok := objects[pipeline.Id]
893+
if !ok || len(objectArr) < 2 {
894+
impl.Logger.Warnw("skipping pipeline with missing object data", "pipelineId", pipeline.Id)
895+
continue
896+
}
897+
appObject := objectArr[0]
898+
envObject := objectArr[1]
882899
if !(appResults[appObject] && envResults[envObject]) {
883900
// if user unauthorized, skip items
884901
continue

0 commit comments

Comments
 (0)