diff --git a/cyclonedx/model/component.py b/cyclonedx/model/component.py index bc7152ae..3f81a1c3 100644 --- a/cyclonedx/model/component.py +++ b/cyclonedx/model/component.py @@ -1689,8 +1689,12 @@ def get_all_nested_components(self, include_self: bool = False) -> set['Componen if include_self: components.add(self) - for c in self.components: - components.update(c.get_all_nested_components(include_self=True)) + stack = list(self.components) + while stack: + current = stack.pop() + if current not in components: + components.add(current) + stack.extend(current.components) return components