Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/php-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
41 changes: 30 additions & 11 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---

Expand Down
54 changes: 54 additions & 0 deletions tests/Unit/NotificationEmailDeduplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

beforeAll(function() {
thold_test_load(dirname(__DIR__, 2) . '/thold_functions.php');
});

beforeEach(function() {
CactiStubs::reset();
CactiStubs::$configOptions['alert_deadnotify_one_mail'] = 'on';
});

test('combined device notifications use the sha256 deduplication path', function() {
$event = [
'from' => ['sender@example.com'],
'to' => 'operator@example.com',
'cc' => '',
'bcc' => '',
'replyto' => '',
'subject' => 'Device is down',
'body' => '<body>Device is down</body>',
'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(');
});
2 changes: 1 addition & 1 deletion thold_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading