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

events/edit API readds deleted attributes already returned by a search #33

Closed
mike1703 opened this issue Dec 20, 2016 · 4 comments
Closed
Assignees

Comments

@mike1703
Copy link

Steps to reproduce:

  • fetch an event (with id: event_id) with my_event = misp.search()
  • delete some attributes from event_id
  • add an attribute with misp.add_attribute(my_event, )
    => the deleted attributes are recreated as they are still included in my_event

workaround:
set my_event['Event']['Attribute'] = [ ] before adding any new attributes.

possible fixes:

  • create a different API which supports deltas which can be uploaded in one go
  • on adding an attribute do not resend the old attributes
@Rafiot
Copy link
Member

Rafiot commented Dec 20, 2016

Just to make sure you use the same path I'd be using (pseudocode):

misp = PyMISP(...)
e = misp.search('foobar')
# delete attributes from e 
misp.add_named_attribute(e, ...)

You're right, all the deleted attributes will be back. I think the easy and clean fix is to set the attributes list to [] in add_named_attribute.

Never mind, this pseudo code should work (https://github.com/MISP/PyMISP/blob/master/pymisp/api.py#L379). How do you delete the attributes?

@mike1703
Copy link
Author

mike1703 commented Dec 21, 2016

I am deleting them with misp.delete_attribute(attribute_id).
The problem is that the following code in _send_attributes just takes your event event = misp.search('foobar'), parses it (so it is based on the event MISP returned to me as a result for the search, adds my new attributes and updates the event. Old attributes are still sent with the event. e.attributes = attributes would be a fix. I just don't know if it will break something else.
https://github.com/MISP/PyMISP/blob/master/pymisp/api.py#L378

e = MISPEvent(self.describe_types)
            e.load(event)
            e.attributes += attributes
            response = self.update_event(event['Event']['id'], json.dumps(e, cls=EncodeUpdate))

@Rafiot Rafiot self-assigned this Dec 21, 2016
@Rafiot
Copy link
Member

Rafiot commented Dec 21, 2016

I'll work on a fix asap. Expect it to be fixed early next year.

Rafiot added a commit that referenced this issue Jan 2, 2017
@Rafiot
Copy link
Member

Rafiot commented Jan 2, 2017

Current master let you mark an attribute as deleted. This is the cleanest way to do it.

Can you give a try and tell me if it is fine for you.

truckydev pushed a commit to truckydev/PyMISP that referenced this issue Jan 4, 2017
@Rafiot Rafiot closed this as completed Jan 7, 2017
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

No branches or pull requests

2 participants