mirror of https://github.com/MISP/MISP
fix: [breakOnDuplicate] on event add fixed, fixes #6917
- add breakOnDuplicate on the event level as a flag - {"Event":{"breakOnDuplicate":1, "info": "foo", ...}} - correctly handle 2 equal objects added to the same event in memorypull/7002/head
parent
8e3ccb3d5f
commit
8bde7d01f4
|
@ -3652,6 +3652,7 @@ class Event extends AppModel
|
|||
if (!$this->checkEventBlockRules($data)) {
|
||||
return 'Blocked by event block rules';
|
||||
}
|
||||
$breakOnDuplicate = !empty($data['Event']['breakOnDuplicate']);
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
if (empty($data['Event']['Attribute']) && empty($data['Event']['Object']) && !empty($data['Event']['published']) && empty($data['Event']['EventReport'])) {
|
||||
$this->Log->create();
|
||||
|
@ -3874,8 +3875,9 @@ class Event extends AppModel
|
|||
}
|
||||
$referencesToCapture = array();
|
||||
if (!empty($data['Event']['Object'])) {
|
||||
foreach ($data['Event']['Object'] as $object) {
|
||||
$result = $this->Object->captureObject($object, $this->id, $user, $this->Log, false);
|
||||
$objectDuplicateCache = [];
|
||||
foreach ($data['Event']['Object'] as $k => $object) {
|
||||
$result = $this->Object->captureObject($object, $this->id, $user, $this->Log, false, $breakOnDuplicate);
|
||||
}
|
||||
foreach ($data['Event']['Object'] as $object) {
|
||||
if (isset($object['ObjectReference'])) {
|
||||
|
|
|
@ -321,6 +321,17 @@ class MispObject extends AppModel
|
|||
);
|
||||
}
|
||||
$newObjectAttributeCount = count($newObjectAttributes);
|
||||
if (!empty($this->__objectDuplicationCheckCache['new'][$object['Object']['template_uuid']])) {
|
||||
foreach ($this->__objectDuplicationCheckCache['new'][$object['Object']['template_uuid']] as $previousNewObject) {
|
||||
if ($newObjectAttributeCount === count($previousNewObject)) {
|
||||
if (empty(array_diff($previousNewObject, $newObjectAttributes))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->__objectDuplicationCheckCache['new'][$object['Object']['template_uuid']][] = $newObjectAttributes;
|
||||
|
||||
if (!isset($this->__objectDuplicationCheckCache[$object['Object']['template_uuid']])) {
|
||||
$this->__objectDuplicationCheckCache[$object['Object']['template_uuid']] = $this->find('all', array(
|
||||
'recursive' => -1,
|
||||
|
@ -892,13 +903,13 @@ class MispObject extends AppModel
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function captureObject($object, $eventId, $user, $log = false, $unpublish = true)
|
||||
public function captureObject($object, $eventId, $user, $log = false, $unpublish = true, $breakOnDuplicate = false)
|
||||
{
|
||||
$this->create();
|
||||
if (!isset($object['Object'])) {
|
||||
$object = array('Object' => $object);
|
||||
}
|
||||
if (!empty($object['Object']['breakOnDuplicate'])) {
|
||||
if (!empty($object['Object']['breakOnDuplicate']) || $breakOnDuplicate) {
|
||||
$duplicate = $this->checkForDuplicateObjects($object, $eventId);
|
||||
if ($duplicate) {
|
||||
$log->create();
|
||||
|
|
Loading…
Reference in New Issue