Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding a Note, Opinion or Relationship #1306

Open
chrisr3d opened this issue Oct 30, 2024 · 0 comments · May be fixed by #1307
Open

Error when adding a Note, Opinion or Relationship #1306

chrisr3d opened this issue Oct 30, 2024 · 0 comments · May be fixed by #1307

Comments

@chrisr3d
Copy link
Member

As Analyst Data - such as Note, Opinion and Relationship - can be attached to many different data layers, including themselves, all the PyMISP objects inheriting from AnalystDataBehaviorMixin will have the 'Note', 'Opinion' and 'Relationship' fields set to an empty list at their creation.
Then, from_dict populates those fields when needed or leave them empty.

This behavior is causing an issue when we want to use our favorite helpers to populate the different data layers with contained information, for example when using add_attribute at the Event or Object level, in the case where the Attribute contains a Note, Opinion or Relationship created with the related PyMISP object.

In order to have a better understanding, here is the situation described with a few lines of code:

from pymisp import MISPEvent, MISPAttribute

event = MISPEvent()

attribute = MISPAttribute()
attribute.from_dict(type='domain', value='circl.lu')
attribute.add_note(note='CIRCL domain')
# at this stage `add_note` generated a MISPNote and used the `from_dict` method defined in the MISPNote class

event.add_attribute(**attribute)
# this is where the issue happens

The issue appears here because of the following succession of events:

  1. In add_attribute, a MISPAttribute is declared, its from_dict method is called
  2. Then the from_dict method of AnalystDataBehaviorMixin is called
  3. It finds the analyst note within the 'Note' field, it is the MISPNote object mentioned in the code sample
  4. This MISPNote object has also a 'Note' field as any other AnalystDataBehaviorMixin object, it is here an empty list
  5. The information describing the note is replaced here with the empty list
  6. An issue is raised here as kwargs is no longer a dict containing the note fields, but an empty list
image

This is my example with an Attribute, but it should also impact any data layer containing a Note, Opinion or Relationship, including when there is a Note or Opinion of another Note or Opinion...

NB: no issue is raised when describing a Note, Opinion or Relationship using JSON format or a python dict but you know... the different helpers are there to make our lives easier, let's use them

@chrisr3d chrisr3d linked a pull request Oct 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant