MISP / MISP

MISP (core software) - Open Source Threat Intelligence and Sharing Platform
https://www.misp-project.org/
GNU Affero General Public License v3.0
5.26k stars 1.38k forks source link

Bug: Emails not sent on Publish (checkPublishFilter() Error) #8523

Open marcnil815 opened 2 years ago

marcnil815 commented 2 years ago

Expected behavior

User creates event and hits the publish button. On publish emails should be sent.

Actual behavior

Emails are not sent. Job fails with a stack trace error in MISP/app/Model/Event.php, line 3106

Steps to reproduce

Unfortunately this is entirely random. It stands to reason that this happens for certain users that are missing a setting, but this has not been confirmed.

Email worker is ok and running (using SimpleBackGoundJobs)

Version

2.4.159

Operating System

Ubuntu LTS

Operating System version

20.04

PHP version

7.4.3

Browser

Any

Browser version

No response

Relevant log output

Error: Notice Error: Undefined offset: 0 in [/var/www/MISP/app/Model/Event.php, line 3106]
(Click to hide stack trace)
Notice Error: Undefined offset: 0 in [/var/www/MISP/app/Model/Event.php, line 3106]

Error: Argument 2 passed to UserSetting::checkPublishFilter() must be of the type array, null given, called in /var/www/MISP/app/Model/Event.php on line 3108
#0 /var/www/MISP/app/Model/Event.php(3108): UserSetting->checkPublishFilter()
#1 /var/www/MISP/app/Console/Command/EventShell.php(291): Event->sendAlertEmail()
#2 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/Shell.php(459): EventShell->alertemail()
#3 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/ShellDispatcher.php(222): Shell->runCommand()
#4 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#5 /var/www/MISP/app/Console/cake.php(45): ShellDispatcher::run()
#6 {main}

Extra attachments

No response

Code of Conduct

marcnil815 commented 2 years ago

So apparently this does for some reason not return an array (null):

$eventForUser = $this->fetchEvent($user, [
                'eventid' => $id, 
                'includeAllTags' => true,
                'includeEventCorrelations' => true,
                'noEventReports' => true,
                'noSightings' => true,
                'metadata' => $metadataOnly,
            ])[0];
iglocska commented 2 years ago

Interesting. It seems like there's a possibility of getUsersWithAccess() and fetchEvent() to disagree. I've pushed a speculative fix for this, it will skip the user that doesn't have access to the event rather than barfing on it and blocking the process.

Also, I've added some logging to capture which events and which users are causing this, you should have log entries in the future under the "User" model and "alert" action in your logs for when this (now silently) fails.

marcnil815 commented 2 years ago

Thanks. I will pull and see if this pops up again.

marcnil815 commented 1 year ago

Alright. The problem seems to be fixed. However, a new one has cropped up preventing the sending of email.

2022-09-22 08:30:57 Error: [JOB ID: 52a737eb-1497-4f4f-b218-3befc2d4c34f] - failed with error code 1. STDERR: Error:
Cannot save log because of validation errors: {"action":["Options : ..."]}`
#0 /var/www/MISP/app/Model/Event.php(2996): Log->createLogEntry()
#1 /var/www/MISP/app/Console/Command/EventShell.php(294): Event->sendAlertEmail()
#2 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/Shell.php(459): EventShell->alertemail()
#3 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/ShellDispatcher.php(222): Shell->runCommand()
#4 /var/www/MISP/app/Lib/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#5 /var/www/MISP/app/Console/cake.php(45): ShellDispatcher::run()
#6 {main}
. STDOUT: .

The changelogs of 162 mention this "Fixes a validation error - found unknown escape character". So I will update to see if this fixes the new issue.

Will close this now as it is fixed. Will open new one with the above if the upgrade does not take care of that.

marcnil815 commented 1 year ago

@iglocska wait...are you trying to log an action that does not exist, and hence the validation fails? I supposed it shouldn't matter, but something fails nonetheless....ironically the very logging that should tell us something about what is happening cannot log because of the very same thing that is happening and throws an exception I guess? :)

I narrowed it down to a specific user, but I cannot see any difference regarding that user compared to any other user.

marcnil815 commented 10 months ago

It seems this still keeps happening. Unfortunately it keeps happening in silence. Anyone else noticing how some users are just not eligible for email on publish and the entire job stops?