diff --git a/.github/workflows/php-unit-tests.yml b/.github/workflows/php-unit-tests.yml index 89eb1ad4..da6cba4a 100644 --- a/.github/workflows/php-unit-tests.yml +++ b/.github/workflows/php-unit-tests.yml @@ -72,8 +72,19 @@ jobs: # Thold contributes no parallel vendor directory or PHPUnit dependency. - name: Build Cacti test image run: | - docker build --tag cacti-web --file cacti-toolchain/docker/Dockerfile cacti-toolchain/docker - docker build --tag cacti-thold-test --file cacti-toolchain/docker/Dockerfile.test cacti-toolchain + for attempt in 1 2 3; do + if docker build --tag cacti-web --file cacti-toolchain/docker/Dockerfile cacti-toolchain/docker && \ + docker build --tag cacti-thold-test --file cacti-toolchain/docker/Dockerfile.test cacti-toolchain; then + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + sleep 10 + fi + done + + echo 'Cacti test image build failed after three attempts.' >&2 + exit 1 - name: Lint every PHP source file run: | diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 5e4f3db6..73630b54 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -35,21 +35,12 @@ jobs: integration-test: runs-on: ${{ matrix.os }} - # A failure against the pinned release is a real failure. The develop entry - # is advisory: it is how a core regression becomes visible here, but it must - # not turn the plugin's own pull requests red. - continue-on-error: ${{ matrix.cacti != 'release/1.2.31' }} - strategy: fail-fast: false matrix: php: ['8.1', '8.2', '8.3', '8.4'] os: [ubuntu-latest] cacti: ['release/1.2.31'] - include: - - php: '8.4' - os: ubuntu-latest - cacti: 'develop' services: mariadb: @@ -95,7 +86,24 @@ jobs: echo "PHP_BINARY=$(command -v php)" >> "$GITHUB_ENV" - name: Run apt-get update - run: sudo apt-get update + run: | + for attempt in 1 2 3; do + if sudo timeout 3m apt-get \ + -o Dpkg::Lock::Timeout=60 \ + -o Acquire::Retries=3 \ + -o Acquire::http::Timeout=30 \ + -o Acquire::https::Timeout=30 \ + update; then + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + sleep 10 + fi + done + + echo 'apt-get update failed after three bounded attempts.' >&2 + exit 1 - name: Install System Dependencies run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping @@ -141,7 +149,18 @@ jobs: run: | cd ${{ github.workspace }}/cacti if [ -f composer.json ]; then - sudo composer install --prefer-dist --no-progress + for attempt in 1 2 3; do + if sudo composer install --prefer-dist --no-progress --no-interaction; then + exit 0 + fi + + if [ "$attempt" -lt 3 ]; then + sleep 10 + fi + done + + echo 'Composer install failed after three attempts.' >&2 + exit 1 fi - name: Create Cacti config.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b7db7d7..08fa0ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * issue#719: Plugin Disabled due to mix of string and int * issue: All Columns checkd on Thresholds page * issue: Special character previous value handling broken on data query indexes with special characters +* security: Replace md5() with sha256 for email dedup cache key (GHSA-gf2h-84m3-q6m3, CWE-1240) --- 1.8.2 --- diff --git a/tests/Unit/NotificationEmailDeduplicationTest.php b/tests/Unit/NotificationEmailDeduplicationTest.php new file mode 100644 index 00000000..ba618eea --- /dev/null +++ b/tests/Unit/NotificationEmailDeduplicationTest.php @@ -0,0 +1,54 @@ + ['sender@example.com'], + 'to' => 'operator@example.com', + 'cc' => '', + 'bcc' => '', + 'replyto' => '', + 'subject' => 'Device is down', + 'body' => 'Device is down', + 'body_text' => 'Device is down', + 'attachments' => [], + 'headers' => [], + 'html' => true, + ]; + + CactiStubs::willReturn('db_fetch_assoc', [[ + 'id' => 42, + 'topic' => 'thold_dhost_mail', + 'event_data' => json_encode($event), + ]]); + + process_device_notifications(0, 'all', 0); + + $source = file_get_contents(dirname(__DIR__, 2) . '/thold_functions.php'); + + expect(CactiStubs::$mail)->toHaveCount(1) + ->and($source)->toContain("hash('sha256', json_encode(") + ->not->toContain('md5(json_encode('); +}); diff --git a/thold_functions.php b/thold_functions.php index 018cf99b..23319ba1 100644 --- a/thold_functions.php +++ b/thold_functions.php @@ -7307,7 +7307,7 @@ function process_device_notifications($pid, $max_records, $prev_suspended) { WHERE id = ?', [$error_code, str_replace("\n", ' ', $error), $nend - $nstart, $r['id']]); } else { - $id = md5(json_encode([$from, $to, $cc, $bcc, $replyto])); + $id = hash('sha256', json_encode([$from, $to, $cc, $bcc, $replyto])); if (!isset($emails[$id])) { $emails[$id]['from'] = $from;