Skip to content

Commit

Permalink
Fix/prevent asset graph cycles (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche authored Dec 12, 2024
1 parent caa5899 commit 7ccbc7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ class Meta:
model = Asset
fields = "__all__"

def validate_parent_assets(self, parent_assets):
"""
Check that the assets graph will not contain cycles
"""
if not self.instance:
return parent_assets
if parent_assets:
for asset in parent_assets:
if self.instance in asset.ancestors_plus_self():
raise serializers.ValidationError(
"errorAssetGraphMustNotContainCycles"
)
return parent_assets


class AssetReadSerializer(AssetWriteSerializer):
folder = FieldsRelatedField()
Expand Down
3 changes: 2 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -979,5 +979,6 @@
"attackPath": "Attack path",
"attackPaths": "Attack paths",
"currentCriticality": "Current criticality",
"residualCriticality": "Residual criticality"
"residualCriticality": "Residual criticality",
"errorAssetGraphMustNotContainCycles": "The asset graph must not contain cycles."
}

0 comments on commit 7ccbc7e

Please sign in to comment.