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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* issue#458: Initialize and validate the active tab before saving view defaults, avoiding a TypeError that disables Syslog and stops processing
* issue#459: Explain that SQL Expression rule previews search only queued incoming messages, so an empty preview is not mistaken for an alert-processing failure
* issue#461: Fit message previews to the available column width instead of cutting them to 100 characters

* issue#456: Avoid PHP 8.6 deprecation warnings during schema checks by using object IDs for the connection cache key

Expand Down
3 changes: 1 addition & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8232,10 +8232,9 @@ function syslog_message_button($message, $device, $program, $facility, $severity
$details = compact('device', 'program', 'facility', 'severity', 'received');
$details['message'] = (string) $message;
$details['rules'] = syslog_message_rule_links($id, $source, $received, $device);
$text = title_trim((string) $message, 100);

return '<button type="button" class="syslogMessageOpen" aria-controls="syslog_message_details" aria-expanded="false" data-message="' .
html_escape(json_encode($details, JSON_INVALID_UTF8_SUBSTITUTE)) . '">' . html_escape($text) . '</button>';
html_escape(json_encode($details, JSON_INVALID_UTF8_SUBSTITUTE)) . '">' . html_escape($details['message']) . '</button>';
}

/**
Expand Down
9 changes: 7 additions & 2 deletions tests/Fixtures/compact_workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ function html_escape_request_var($key) { return html_escape(get_request_var($key
function cacti_sizeof($value) { return count($value); }
function api_plugin_hook($name) {}
function api_plugin_user_realm_auth($page) { return true; }
function db_fetch_assoc_prepared($sql, $params = []) { return [['id' => 1]]; }
function is_realm_allowed($realm) { return true; }
function read_config_option($name, $force = false) { return ''; }
require dirname(__DIR__, 2) . '/includes/functions.php';
$saved_choices_json = '{}';
$saved_fields_json = html_escape(json_encode(['host'=>'Host','message'=>'Message','program'=>'Program','logtime'=>'Date','priority'=>'Priority']));
$saved_tree_json = html_escape(json_encode(['AND',['predicate','host','=','10.0.0.5'],['predicate','logtime','last','86400']]));
$saved_searches = [['id'=>7,'name'=>'Router investigation','is_global'=>'','user'=>'tester']];
$saved_active = 7; $saved_admin = true;
$saved_active = 7; $saved_admin = true; $saved_share = true; $username = 'tester';
$item_rows = [50=>'50',100=>'100'];$trimvals = [0=>'Fit column',75=>'75 Chars',1024=>'All Text'];$page_refresh_interval = [0=>'Paused',300=>'5 Minutes'];
$source = file_get_contents(dirname(__DIR__, 2) . '/syslog.php');
$start = strpos($source, "<form id='syslog_form'"); $end = strpos($source, '</form>', $start)+7;
echo '<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/main.css"><link rel="stylesheet" href="/jquery-ui.css"><link rel="stylesheet" href="/search.css"><style>body{width:auto;font:13px Arial;margin:8px;color:#23362f;background:#fff}button,input,select{font:inherit;padding:5px;border:1px solid #bbc7bf;border-radius:3px}table{border-collapse:collapse}th{text-align:left;background:#e8eee9;padding:8px}h2{font-size:15px}</style><script src="/jquery.js"></script><script src="/jquery-ui.js"></script><script src="/jquery.timepicker.js"></script><script src="/functions.js"></script></head><body><h2>System Logs &nbsp; | &nbsp; Alert Logs</h2>';
eval('?>'.substr($source,$start,$end-$start));
echo '<div id="syslog_workspace"><div class="syslogResultsMain"><table><thead><tr><th>Time</th><th>Device</th><th>Program</th><th>Message</th><th>Facility</th><th>Severity</th></tr></thead><tbody>';
$priorities = ['emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug'];
foreach(range(1,17) as $i) echo '<tr class="syslogRow '.syslog_priority_class($i % 8).'"><td>2026-09-13 00:12:42</td><td>10.0.0.5</td><td>kernel</td><td class="syslogMessage">'.syslog_message_button('nf_conntrack: table full, dropping packet <script>alert("unsafe")</script>','10.0.0.5','kernel','kern',$priorities[$i % 8],'2026-09-13 00:12:42', 100 + $i, $i === 17 ? 'removed' : 'main').'</td><td>kern</td><td>'.$priorities[$i % 8].'</td></tr>';
$message = 'nf_conntrack: table full, dropping packet <script>alert("unsafe")</script>';
$long_message = $message . ' ' . str_repeat('width preview ', 4);
foreach(range(1,17) as $i) echo '<tr class="syslogRow '.syslog_priority_class($i % 8).'"><td>2026-09-13 00:12:42</td><td>10.0.0.5</td><td>kernel</td><td class="syslogMessage">'.syslog_message_button($i === 1 ? $long_message : $message,'10.0.0.5','kernel','kern',$priorities[$i % 8],'2026-09-13 00:12:42', 100 + $i, $i === 17 ? 'removed' : 'main').'</td><td>kern</td><td>'.$priorities[$i % 8].'</td></tr>';
echo '</tbody></table></div>';
$start = strpos($source,"<aside id='syslog_message_details'");$end = strpos($source,'</aside></div>', $start)+strlen('</aside></div>');
eval('?>'.substr($source,$start,$end-$start));
Expand Down
17 changes: 17 additions & 0 deletions tests/Security/MessageDetailsEscapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@
expect($data['message'])->toBe($message, 'Complete log details must survive serialization');
expect($data['device'])->toBe('router" onmouseover="bad', 'Complete log details must survive serialization');
});

it('preserves long escaped messages in both the preview and details', function ($message) {
syslog_load_plugin_source('includes/functions.php');

$html = syslog_message_button($message, 'router', 'kernel', 'kern', 'warning', '2026-11-17 00:00:00');

preg_match('/<button[^>]*>(.*?)<\/button>/s', $html, $preview);
preg_match('/data-message="([^"]*)"/', $html, $details);

expect(html_entity_decode($preview[1], ENT_QUOTES, 'UTF-8'))->toBe($message)
->and(strpos($preview[1], '<script>'))->toBeFalse()
->and(json_decode(html_entity_decode($details[1], ENT_QUOTES, 'UTF-8'), true)['message'])->toBe($message);
})->with([
'ASCII' => str_repeat('message text ', 30),
'Unicode' => str_repeat('接口状态正常 ', 30),
'HTML' => str_repeat('message text ', 12) . '<script>alert("log")</script> & "quoted"'
]);
18 changes: 17 additions & 1 deletion tests/browser/compact_workspace.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {execFileSync} = require('node:child_process');
const assert = require('node:assert/strict');
const root = path.resolve(__dirname, '../..');
const cacti = process.env.CACTI_ROOT || path.resolve(root, '../cacti');
const longMessage = 'nf_conntrack: table full, dropping packet <script>alert("unsafe")</script> ' + 'width preview '.repeat(4);
const fixture = execFileSync('php', [path.join(root, 'tests/Fixtures/compact_workspace.php')], {encoding: 'utf8'});
(async()=>{
const browser=await chromium.launch({headless:true,executablePath:process.env.CHROMIUM_PATH,args:['--no-sandbox']});
Expand All @@ -24,6 +25,15 @@ const fixture = execFileSync('php', [path.join(root, 'tests/Fixtures/compact_wor
});
await page.goto('http://fixture/'); await page.waitForTimeout(250);
assert.deepEqual(errors,[]);
const messageButton = page.locator('.syslogMessageOpen').first();
assert.equal(await messageButton.textContent(), longMessage, 'Preview retains text beyond 100 characters');
const widePreview = await messageButton.evaluate(button => {
const range = document.createRange();
range.setStart(button.firstChild, 110);
range.setEnd(button.firstChild, 111);
return { characterRight: range.getBoundingClientRect().right, buttonRight: button.getBoundingClientRect().right };
});
assert(widePreview.characterRight <= widePreview.buttonRight, 'Characters beyond 100 are visible when the column has room');
// The filter panel is collapsed by default; open it before exercising its controls.
assert.equal(await page.locator('#syslog_search_content').isVisible(), false, 'Filter panel starts collapsed');
assert.equal(await page.locator('#syslog_search_summary').isVisible(), true, 'Collapsed panel shows the query summary');
Expand All @@ -44,8 +54,10 @@ const fixture = execFileSync('php', [path.join(root, 'tests/Fixtures/compact_wor
const originalColor = await page.locator('.syslogRow').first().evaluate(row=>getComputedStyle(row).backgroundColor);
assert.notEqual(originalColor,'rgb(255, 255, 255)');
await page.locator('.syslogMessageOpen').first().click();
assert.equal(await page.locator('#syslog_details_raw').textContent(),'nf_conntrack: table full, dropping packet <script>alert("unsafe")</script>');
assert.equal(await page.locator('#syslog_details_raw').textContent(),longMessage);
assert.equal(await page.locator('#syslog_message_details script').count(),0);
await page.mouse.move(0, 0);
await page.waitForFunction(color => getComputedStyle(document.querySelector('.syslogRow')).backgroundColor === color, originalColor);
assert.equal(await page.locator('.syslogRow').first().evaluate(row=>getComputedStyle(row).backgroundColor),originalColor,'Selection retains severity color');
const alarm = page.locator('[data-rule="alarm"]');
const removal = page.locator('[data-rule="removal"]');
Expand Down Expand Up @@ -80,6 +92,10 @@ const fixture = execFileSync('php', [path.join(root, 'tests/Fixtures/compact_wor
assert.equal(await page.locator('#syslog_view_options #rows').count(),0,'Results limit no longer hides in view options');
await page.keyboard.press('Escape');assert.equal(await page.locator('#save').isVisible(),false);
await page.setViewportSize({width:390,height:844});if (process.env.TEST_ARTIFACT_DIR) await page.screenshot({path:path.join(process.env.TEST_ARTIFACT_DIR, 'syslog-workspace-mobile.png'),fullPage:true});
assert.equal(await messageButton.textContent(), longMessage, 'Narrow layouts retain the complete preview text');
const narrowPreview = await messageButton.evaluate(button => ({width: button.clientWidth, content: button.scrollWidth, ellipsis: getComputedStyle(button).textOverflow}));
assert(narrowPreview.content > narrowPreview.width, 'Long previews overflow their own button on narrow screens');
assert.equal(narrowPreview.ellipsis, 'ellipsis', 'The browser controls visual truncation');
const overflow=await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth);assert.equal(overflow,false,'Page must not overflow horizontally');
await page.locator('#refresh_results').click();assert.equal(await page.evaluate(()=>Object.hasOwn(posts.at(-1),'rfilter')),false);
// A saved expanded preference reopens the panel on reload; an active search error forces it open even when collapse is stored.
Expand Down
Loading