Skip to content

Commit

Permalink
refactor to reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Zavhorodnii committed May 31, 2024
1 parent e5f68f8 commit 4b7d062
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions pkg/security/risks/builtin/missing_network_segmentation_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,28 @@ func (r *MissingNetworkSegmentationRule) GenerateRisks(input *types.Model) ([]*t
continue
}

if technicalAsset.Type == types.Datastore || technicalAsset.Confidentiality >= types.Confidential || technicalAsset.Integrity >= types.Critical || technicalAsset.Availability >= types.Critical {
// now check for any other same-network assets of certain types which have no direct connection
for _, sparringAssetCandidateId := range keys { // so inner loop again over all assets
if technicalAsset.Id != sparringAssetCandidateId {
sparringAssetCandidate := input.TechnicalAssets[sparringAssetCandidateId]
if sparringAssetCandidate.Technologies.GetAttribute(types.IsLessProtectedType) &&
technicalAsset.IsSameTrustBoundaryNetworkOnly(input, sparringAssetCandidateId) &&
!technicalAsset.HasDirectConnection(input, sparringAssetCandidateId) &&
!sparringAssetCandidate.Technologies.GetAttribute(types.IsCloseToHighValueTargetsTolerated) {
highRisk := technicalAsset.Confidentiality == types.StrictlyConfidential ||
technicalAsset.Integrity == types.MissionCritical || technicalAsset.Availability == types.MissionCritical
risks = append(risks, r.createRisk(technicalAsset, highRisk))
break
}
}
if technicalAsset.Type != types.Datastore &&
technicalAsset.Confidentiality < types.Confidential &&
technicalAsset.Integrity < types.Critical &&
technicalAsset.Availability < types.Critical {
continue
}

// now check for any other same-network assets of certain types which have no direct connection
for _, sparringAssetCandidateId := range keys { // so inner loop again over all assets
if technicalAsset.Id == sparringAssetCandidateId {
continue
}

sparringAssetCandidate := input.TechnicalAssets[sparringAssetCandidateId]
if sparringAssetCandidate.Technologies.GetAttribute(types.IsLessProtectedType) &&
technicalAsset.IsSameTrustBoundaryNetworkOnly(input, sparringAssetCandidateId) &&
!technicalAsset.HasDirectConnection(input, sparringAssetCandidateId) &&
!sparringAssetCandidate.Technologies.GetAttribute(types.IsCloseToHighValueTargetsTolerated) {
highRisk := technicalAsset.Confidentiality == types.StrictlyConfidential ||
technicalAsset.Integrity == types.MissionCritical || technicalAsset.Availability == types.MissionCritical
risks = append(risks, r.createRisk(technicalAsset, highRisk))
break
}
}
}
Expand Down

0 comments on commit 4b7d062

Please sign in to comment.