From 7f935f4cec2a6b276fd0b0ba5a9e646d37946f5c Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 30 Jan 2024 16:54:46 +0100 Subject: [PATCH 1/2] chg: [internal] Faster check for session destruction --- app/Model/User.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Model/User.php b/app/Model/User.php index 6c6cea504..b0d1d0358 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -2078,12 +2078,10 @@ class User extends AppModel return false; } - $cutoff = $redis->get('misp:session_destroy:' . $id); - $allcutoff = $redis->get('misp:session_destroy:all'); + list($cutoff, $allcutoff) = $redis->mGet(['misp:session_destroy:' . $id, 'misp:session_destroy:all']); if ( empty($cutoff) || ( - !empty($cutoff) && !empty($allcutoff) && $allcutoff < $cutoff ) From c2811888e425ebbdca41fd856ae02fe1a50f34bd Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Tue, 30 Jan 2024 20:30:39 +0100 Subject: [PATCH 2/2] chg: [internal] Faster freetext parsing --- app/Lib/Tools/ComplexTypeTool.php | 11 +++++------ app/Test/ComplexTypeToolTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/Lib/Tools/ComplexTypeTool.php b/app/Lib/Tools/ComplexTypeTool.php index e9e4e123e..25ddbdfea 100644 --- a/app/Lib/Tools/ComplexTypeTool.php +++ b/app/Lib/Tools/ComplexTypeTool.php @@ -308,14 +308,13 @@ class ComplexTypeTool */ private function parseFreetext($input) { - $input = str_replace("\xc2\xa0", ' ', $input); // non breaking space to normal space - $input = preg_replace('/\p{C}+/u', ' ', $input); - $iocArray = preg_split("/\r\n|\n|\r|\s|\s+|,|\<|\>|;/", $input); + // convert non breaking space to normal space and all unicode chars from "other" category + $input = preg_replace("/\p{C}+|\xc2\xa0/u", ' ', $input); + $iocArray = preg_split("/\r\n|\n|\r|\s|\s+|,|<|>|;/", $input); preg_match_all('/\"([^\"]+)\"/', $input, $matches); - foreach ($matches[1] as $match) { - $iocArray[] = $match; - } + array_push($iocArray, ...$matches[1]); + return $iocArray; } diff --git a/app/Test/ComplexTypeToolTest.php b/app/Test/ComplexTypeToolTest.php index 54acead69..16d4a6273 100644 --- a/app/Test/ComplexTypeToolTest.php +++ b/app/Test/ComplexTypeToolTest.php @@ -527,10 +527,31 @@ EOT; public function testCheckFreeTextNonBreakableSpace(): void { $complexTypeTool = new ComplexTypeTool(); + $results = $complexTypeTool->checkFreeText("127.0.0.1\xc2\xa0127.0.0.2"); $this->assertCount(2, $results); $this->assertEquals('127.0.0.1', $results[0]['value']); $this->assertEquals('ip-dst', $results[0]['default_type']); + + $results = $complexTypeTool->checkFreeText("127.0.0.1\xc2\xa0\xc2\xa0127.0.0.2"); + $this->assertCount(2, $results); + $this->assertEquals('127.0.0.1', $results[0]['value']); + $this->assertEquals('ip-dst', $results[0]['default_type']); + } + + public function testCheckFreeTextControlCharToSpace(): void + { + $complexTypeTool = new ComplexTypeTool(); + + $results = $complexTypeTool->checkFreeText("127.0.0.1\x1d127.0.0.2"); + $this->assertCount(2, $results); + $this->assertEquals('127.0.0.1', $results[0]['value']); + $this->assertEquals('ip-dst', $results[0]['default_type']); + + $results = $complexTypeTool->checkFreeText("127.0.0.1\x1d\x1d127.0.0.2"); + $this->assertCount(2, $results); + $this->assertEquals('127.0.0.1', $results[0]['value']); + $this->assertEquals('ip-dst', $results[0]['default_type']); } public function testCheckFreeTextQuoted(): void