mirror of https://github.com/MISP/MISP
chg: [workflow:normalizeData] Gracefully cath exception and provide more feedback when supplying wrong input data
Fix #9344pull/9370/head
parent
8d01368bf7
commit
2253338b65
|
@ -172,6 +172,12 @@ class WorkflowsController extends AppController
|
|||
{
|
||||
if ($this->request->is('post') || $this->request->is('put')) {
|
||||
$blockingErrors = [];
|
||||
if (!JsonTool::isValid($this->request->data['Workflow']['data'])) {
|
||||
return $this->RestResponse->viewData([
|
||||
'success' => false,
|
||||
'outcome' => __('Invalid JSON'),
|
||||
], $this->response->type());
|
||||
}
|
||||
$data = JsonTool::decode($this->request->data['Workflow']['data']);
|
||||
$result = $this->Workflow->executeWorkflow($workflow_id, $data, $blockingErrors);
|
||||
if (!empty($logging) && empty($result['success'])) {
|
||||
|
|
|
@ -522,7 +522,25 @@ class Workflow extends AppModel
|
|||
$workflow = $this->__incrementWorkflowExecutionCount($workflow);
|
||||
$walkResult = [];
|
||||
$debugData = ['original' => $data];
|
||||
$data = $this->__normalizeDataForTrigger($triggerModule, $data);
|
||||
$conversionFailure = false;
|
||||
try {
|
||||
$data = $this->__normalizeDataForTrigger($triggerModule, $data);
|
||||
} catch (Exception $e) {
|
||||
$conversionFailure = true;
|
||||
$message = __('Error while normalizing data for trigger. Error:' . PHP_EOL . $e->getMessage());
|
||||
}
|
||||
if ($data === false) {
|
||||
$conversionFailure = true;
|
||||
$message = __('Error while normalizing data for trigger. Invalid input.');
|
||||
}
|
||||
if ($conversionFailure) {
|
||||
$this->logExecutionIfDebug($workflow, $message);
|
||||
return [
|
||||
'outcomeText' => 'failure' . sprintf(' %s', $message),
|
||||
'walkResult' => [],
|
||||
'success' => false,
|
||||
];
|
||||
}
|
||||
$debugData['normalized'] = $data;
|
||||
$for_path = !empty($triggerModule->blocking) ? GraphWalker::PATH_TYPE_BLOCKING : GraphWalker::PATH_TYPE_NON_BLOCKING;
|
||||
$this->sendRequestToDebugEndpointIfDebug($workflow, [], '/init?type=' . $for_path, $debugData);
|
||||
|
@ -710,10 +728,10 @@ class Workflow extends AppModel
|
|||
return $success;
|
||||
}
|
||||
|
||||
private function __normalizeDataForTrigger($triggerClass, array $data): array
|
||||
private function __normalizeDataForTrigger($triggerClass, array $data)
|
||||
{
|
||||
if (method_exists($triggerClass, 'normalizeData')) {
|
||||
return $triggerClass->normalizeData($data);
|
||||
$data = $triggerClass->normalizeData($data);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ class Module_post_after_save extends WorkflowBaseTriggerModule
|
|||
public function normalizeData(array $data)
|
||||
{
|
||||
parent::normalizeData($data);
|
||||
|
||||
if (empty($data['Post'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->Thread = ClassRegistry::init('Thread');
|
||||
$thread = $this->Thread->find('first', [
|
||||
'recursive' => -1,
|
||||
|
|
|
@ -26,6 +26,10 @@ class Module_sighting_after_save extends WorkflowBaseTriggerModule
|
|||
$this->Event = ClassRegistry::init('Event');
|
||||
$this->Attribute = ClassRegistry::init('Attribute');
|
||||
|
||||
if (empty($data['Sighting'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We are missing data such as tags or objects.
|
||||
$event = $this->Event->quickFetchEvent($data['Sighting']['Event']['id']);
|
||||
$attribute = $this->Attribute->fetchAttribute($data['Sighting']['Attribute']['id']);
|
||||
|
|
Loading…
Reference in New Issue