Skip to content

Commit

Permalink
fix: Do not let a user pass a full dict as tagname
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jul 16, 2024
1 parent 3a65c59 commit 2236890
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pymisp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3789,7 +3789,7 @@ def change_sharing_group_on_entity(self, misp_entity: MISPEvent | MISPAttribute

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.
Expand All @@ -3801,8 +3801,12 @@ def tag(self, misp_entity: AbstractMISP | str | dict[str, Any], tag: MISPTag | s
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
Expand Down

0 comments on commit 2236890

Please sign in to comment.