Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

fix(core): list template enrichers visible to owner or public, matching launch lookup

dextmorgn1299bb880f6b
diff --git a/flowsint-core/src/flowsint_core/core/services/enricher_service.py b/flowsint-core/src/flowsint_core/core/services/enricher_service.py
index 69afca76..25196d5e 100644
--- a/flowsint-core/src/flowsint_core/core/services/enricher_service.py
+++ b/flowsint-core/src/flowsint_core/core/services/enricher_service.py
@@ -79,7 +79,11 @@ class EnricherService(BaseService):
self, category: Optional[str], user_id: UUID, enricher_registry: Any
) -> list:
base_enrichers = self.get_enrichers(category, user_id, enricher_registry)
- template_enrichers = self._enricher_template_repo.get_by_owner(
+ # Owner-or-public, matching what the launch path resolves a template
+ # name against. Listing only owned templates left another user's public
+ # template launchable but invisible, so its params_schema never reached
+ # the UI and the launch failed on a missing required param.
+ template_enrichers = self._enricher_template_repo.get_by_owner_or_public(
user_id, category
)
for template in template_enrichers:
diff --git a/flowsint-core/tests/services/test_enricher_service.py b/flowsint-core/tests/services/test_enricher_service.py
index 401574ed..b865c83f 100644
--- a/flowsint-core/tests/services/test_enricher_service.py
+++ b/flowsint-core/tests/services/test_enricher_service.py
@@ -120,3 +120,89 @@ class TestGetAllEnrichers:
[template] = self._list(db_session, user)
assert template.params_schema == []
+
+
+class TestTemplateVisibility:
+ """The listing must agree with the launch path, which resolves a template
+ name against owner-or-public."""
+
+ def _setup(self, db_session):
+ ProfileFactory._meta.sqlalchemy_session = db_session
+ EnricherTemplateFactory._meta.sqlalchemy_session = db_session
+
+ def _list(self, db_session, user, category=None):
+ registry = MagicMock()
+ registry.list.return_value = []
+ registry.list_by_input_type.return_value = []
+ service = EnricherService(
+ db=db_session,
+ custom_type_repo=CustomTypeRepository(db_session),
+ enricher_template_repo=EnricherTemplateRepository(db_session),
+ )
+ return service.get_all_enrichers(category, user.id, registry)
+
+ def test_another_owners_public_template_is_listed(self, db_session):
+ self._setup(db_session)
+ viewer = ProfileFactory()
+ stranger = ProfileFactory()
+ EnricherTemplateFactory(
+ owner=stranger, name="shared-lookup", is_public=True, content=_content([])
+ )
+
+ assert [t.name for t in self._list(db_session, viewer)] == ["shared-lookup"]
+
+ def test_another_owners_private_template_stays_hidden(self, db_session):
+ self._setup(db_session)
+ viewer = ProfileFactory()
+ stranger = ProfileFactory()
+ EnricherTemplateFactory(
+ owner=stranger, name="private-lookup", is_public=False, content=_content([])
+ )
+
+ assert self._list(db_session, viewer) == []
+
+ def test_a_listed_public_template_carries_its_params_schema(self, db_session):
+ self._setup(db_session)
+ viewer = ProfileFactory()
+ stranger = ProfileFactory()
+ EnricherTemplateFactory(
+ owner=stranger,
+ name="shared-lookup",
+ is_public=True,
+ content=_content([{"name": "SHARED_TOKEN", "required": True}]),
+ )
+
+ [template] = self._list(db_session, viewer)
+
+ assert template.params_schema == [
+ {
+ "name": "SHARED_TOKEN",
+ "type": "vaultSecret",
+ "required": True,
+ "description": None,
+ }
+ ]
+ assert template.required_params is True
+
+ def test_the_category_filter_still_applies_to_public_templates(self, db_session):
+ self._setup(db_session)
+ viewer = ProfileFactory()
+ stranger = ProfileFactory()
+ EnricherTemplateFactory(
+ owner=stranger,
+ name="ip-lookup",
+ category="Ip",
+ is_public=True,
+ content=_content([]),
+ )
+ EnricherTemplateFactory(
+ owner=stranger,
+ name="username-lookup",
+ category="Username",
+ is_public=True,
+ content=_content([]),
+ )
+
+ listed = self._list(db_session, viewer, category="Ip")
+
+ assert [t.name for t in listed] == ["ip-lookup"]