Bug: MISP 2.5.46 server pull stops pagination early when protected events are filtered from a page
Actual behavior
MISP 2.5.46 server pull stops pagination early when protected events are filtered from a page
Expected behavior
A full description can be found in "Steps to reproduce"
Steps to reproduce
Steps to reproduce
Set up two MISP instances, both running MISP 2.5.46:
- Remote MISP: source of the events
- Local MISP: configured to pull events from the remote instance
Configure a server pull on the local instance and perform a full pull using:
sudo -u www-data /var/www/MISP/app/Console/cake Server pull <sync-user-id> <server-id>On the remote MISP, ensure that there are more than 10,000 published events.
Ensure that at least one event within the first 10,000 events returned by the following request is protected (
Event.protected = 1) and is not accessible to the pulling instance.The relevant endpoint is:
POST /events/indexwith parameters equivalent to:
minimal=1 published=1 page=1 limit=10000 sort=id direction=ascOn the remote MISP, the request is handled by:
/var/www/MISP/app/Controller/EventsController.phpin the subroutine:
private function __indexRestResponse(array $passedArgs)In MISP 2.5.46, the initial database query is performed around line 934:
$events = $absoluteTotal === 0 ? [] : $this->Event->find('all', $rules);With the above parameters, this query returns 10,000 events.
Because
minimal=1, the events are subsequently processed in theelse { // minimal }block around line 1036.Protected events are removed around lines 1038–1041:
if ($event['Event']['protected'] && !isset($protectedEventsByInstanceKey[$event['Event']['id']])) { unset($events[$key]); continue; }If exactly one of the 10,000 events is protected, the resulting REST response therefore contains 9,999 events.
On the local MISP, the response is processed by:
/var/www/MISP/app/Model/Server.phpin:
private function getEventIdsFromServer( ServerSyncTool $serverSync, $all = false, $ignoreFilterRules = false, $force = false )In MISP 2.5.46, the paginated request is made around line 1143:
$eventArray = $this->getEventIndexFromServer( $serverSync, $ignoreFilterRules, ['page' => $page, 'limit' => $pageSize] );The number of received events is then determined around line 1144:
$fetched = count($eventArray);With the protected event filtered out by the remote server, the local instance receives:
fetched = 9999The pagination is then terminated around lines 1183–1185 because
$fetchedis smaller than$pageSize:if ($remoteIgnoredPagination || $notAdvancing || $fetched < $pageSize) { break; }Consequently, page 2 and all subsequent pages are not requested, even though the remote instance still has additional events.
Observed result
For example, with:
page size: 10000
events returned by DB: 10000
protected events: 1
events returned via API: 9999the local server interprets the response as the last page and stops pulling.
In my test case, the event I was looking for was located on page 83. It was not pulled before the fix because pagination stopped after page 1.
Workaround
The issue can be worked around by removing the $fetched < $pageSize condition from the pagination termination check in:
/var/www/MISP/app/Model/Server.phpsubroutine:
private function getEventIdsFromServer(
ServerSyncTool $serverSync,
$all = false,
$ignoreFilterRules = false,
$force = false
)around lines 1183–1185 in MISP 2.5.46.
Current code:
if ($remoteIgnoredPagination || $notAdvancing || $fetched < $pageSize) {
break;
}Tested workaround:
if ($remoteIgnoredPagination || $notAdvancing) {
break;
}Why this works
$fetched is the number of events remaining after the remote /events/index response has already been filtered.
Therefore, $fetched < $pageSize does not necessarily mean that the remote page was the last page.
For example:
Remote query:
10,000 events
Protected events removed:
1 event
Response received by local MISP:
9,999 eventsThe existing code interprets 9,999 < 10,000 as the last page and stops pagination.
After removing this condition, pagination continues until one of the other two conditions is met:
$remoteIgnoredPaginationor:
$notAdvancingThe final page is correctly terminated by the existing check earlier in the loop:
if ($fetched === 0) {
break;
}Verification
With the workaround applied, the same server pull proceeded as follows:
page=1 fetched=9999
page=2 fetched=10000
page=3 fetched=10000
...
page=83 fetched=5981
page=84 fetched=0The previously missing event was located on page 83 and was successfully included in the pull.
No other changes to the server synchronization configuration were required.
Suggested permanent fix
The pagination logic should not use the number of events remaining after response-side filtering ($fetched) as an indication that the remote page was the last page.
A permanent fix should retain a reliable indication of whether the remote result set itself reached the requested page size, independently of events subsequently removed by filtering.
Version
2.5.46
Operating System
Ubuntu
Operating System version
24.04
PHP version
8.3
Browser
No response
Browser version
No response
Relevant log output
Extra attachments
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: MISP/MISP