From 5a17f057e776e4b25f55e7131b8e47a08ff9048f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 16 Jul 2024 12:44:47 +0200 Subject: [PATCH] fix: Do not let a user pass a full dict as tagname --- pymisp/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index 8cf8380..2a32d10 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -3823,7 +3823,7 @@ class PyMISP: raise PyMISPError('The misp_entity must be MISPEvent, MISPObject or MISPAttribute') - def tag(self, misp_entity: AbstractMISP | str | dict[str, Any], tag: MISPTag | str, + def tag(self, misp_entity: AbstractMISP | str | dict[str, Any], tag: MISPTag | str | dict[str, Any], local: bool = False, relationship_type: str | None = None) -> dict[str, Any] | list[dict[str, Any]]: """Tag an event or an attribute. @@ -3835,8 +3835,12 @@ class PyMISP: uuid = get_uuid_or_id_from_abstract_misp(misp_entity) if isinstance(tag, MISPTag): tag_name = tag.name if 'name' in tag else "" + elif isinstance(tag, dict): + tag_name = tag.get('name', '') else: tag_name = tag + if not tag_name: + raise PyMISPError('tag must be a MISPTag object, a dict with a name key, or a string, and it cannot be empty.') to_post = {'uuid': uuid, 'tag': tag_name, 'local': local} if relationship_type: to_post['relationship_type'] = relationship_type