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 7efb65d commit 73788dc
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions pkg/security/risks/builtin/missing_identity_store_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,27 @@ func (r *MissingIdentityStoreRule) GenerateRisks(input *types.Model) ([]*types.R
for _, id := range input.SortedTechnicalAssetIDs() { // use the sorted one to always get the same tech asset with the highest sensitivity as example asset
technicalAsset := input.TechnicalAssets[id]
for _, commLink := range technicalAsset.CommunicationLinksSorted() { // use the sorted one to always get the same tech asset with the highest sensitivity as example asset
if commLink.Authorization == types.EndUserIdentityPropagation {
riskIdentified = true
targetAsset := input.TechnicalAssets[commLink.TargetId]
if impact == types.LowImpact {
mostRelevantAsset = targetAsset
if targetAsset.HighestProcessedConfidentiality(input) >= types.Confidential ||
targetAsset.HighestProcessedIntegrity(input) >= types.Critical ||
targetAsset.HighestProcessedAvailability(input) >= types.Critical {
impact = types.MediumImpact
}
}
if targetAsset.Confidentiality >= types.Confidential ||
targetAsset.Integrity >= types.Critical ||
targetAsset.Availability >= types.Critical {
if commLink.Authorization != types.EndUserIdentityPropagation {
continue
}
riskIdentified = true
targetAsset := input.TechnicalAssets[commLink.TargetId]
if impact == types.LowImpact {
mostRelevantAsset = targetAsset
if targetAsset.HighestProcessedConfidentiality(input) >= types.Confidential ||
targetAsset.HighestProcessedIntegrity(input) >= types.Critical ||
targetAsset.HighestProcessedAvailability(input) >= types.Critical {
impact = types.MediumImpact
}
// just for referencing the most interesting asset
if technicalAsset.HighestSensitivityScore() > mostRelevantAsset.HighestSensitivityScore() {
mostRelevantAsset = technicalAsset
}
}
if targetAsset.Confidentiality >= types.Confidential ||
targetAsset.Integrity >= types.Critical ||
targetAsset.Availability >= types.Critical {
impact = types.MediumImpact
}
// just for referencing the most interesting asset
if technicalAsset.HighestSensitivityScore() > mostRelevantAsset.HighestSensitivityScore() {
mostRelevantAsset = technicalAsset
}
}
}
Expand Down

0 comments on commit 73788dc

Please sign in to comment.