Skip to content

Commit b8e6edc

Browse files
fix(security): defense-in-depth hardening for plugin_syslog (#303)
* ci: add CodeQL for javascript-typescript, python, ruby * fix(ci): use specific runner labels, fix codeql concurrency * fix(security): defense-in-depth hardening for plugin_syslog Automated fixes: - XSS: escape request variables in HTML output - SQLi: convert string-concat queries to prepared statements - Deserialization: add allowed_classes=>false - Temp files: replace rand() with tempnam() Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * security: replace legacy XML import with secure helper in plugin_syslog --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: TheWitness <thewitness@cacti.net>
1 parent 16792b6 commit b8e6edc

5 files changed

Lines changed: 53 additions & 45 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [main, master, develop, regression-audit]
6+
paths-ignore:
7+
- "**/*.php"
8+
- "**/*.md"
9+
pull_request:
10+
branches: [main, master, develop, regression-audit]
11+
paths-ignore:
12+
- "**/*.php"
13+
- "**/*.md"
14+
schedule:
15+
- cron: "30 1 * * 1"
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: codeql-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 20
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
language: ["javascript-typescript", "python", "ruby"]
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
38+
- name: Initialize CodeQL
39+
uses: github/codeql-action/init@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3
40+
with:
41+
languages: ${{ matrix.language }}
42+
- name: Autobuild
43+
uses: github/codeql-action/autobuild@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3
44+
- name: Perform CodeQL Analysis
45+
uses: github/codeql-action/analyze@b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d # v3
46+
with:
47+
category: "/language:${{ matrix.language }}"

syslog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ function syslog_filter($sql_where, $tab) {
11911191
<?php print __('From', 'syslog');?>
11921192
</td>
11931193
<td>
1194-
<input type='text' id='date1' size='18' value='<?php print get_request_var('date1');?>'>
1194+
<input type='text' id='date1' size='18' value='<?php print html_escape_request_var('date1'); ?>'>
11951195
</td>
11961196
<td>
11971197
<i title='<?php print __esc('Start Date Selector', 'syslog');?>' class='calendar fa fa-calendar-alt' id='startDate'></i>
@@ -1200,7 +1200,7 @@ function syslog_filter($sql_where, $tab) {
12001200
<?php print __('To', 'syslog');?>
12011201
</td>
12021202
<td>
1203-
<input type='text' id='date2' size='18' value='<?php print get_request_var('date2');?>'>
1203+
<input type='text' id='date2' size='18' value='<?php print html_escape_request_var('date2'); ?>'>
12041204
</td>
12051205
<td>
12061206
<i title='<?php print __esc('End Date Selector', 'syslog');?>' class='calendar fa fa-calendar-alt' id='endDate'></i>
@@ -1472,7 +1472,7 @@ function syslog_filter($sql_where, $tab) {
14721472
</select>
14731473
</td>
14741474
<?php } else { ?>
1475-
<input type='hidden' id='removal' value='<?php print get_request_var('removal');?>'>
1475+
<input type='hidden' id='removal' value='<?php print html_escape_request_var('removal'); ?>'>
14761476
<?php } ?>
14771477
<?php if (get_nfilter_request_var('tab') == 'syslog') { ?>
14781478
<td>

syslog_alerts.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -934,20 +934,7 @@ function import() {
934934
}
935935

936936
function alert_import() {
937-
$import_text = get_nfilter_request_var('import_text');
938-
939-
if (trim($import_text) != '') {
940-
/* textbox input */
941-
$xml_data = $import_text;
942-
} elseif (($_FILES['import_file']['tmp_name'] != 'none') && ($_FILES['import_file']['tmp_name'] != '')) {
943-
/* file upload */
944-
$fp = fopen($_FILES['import_file']['tmp_name'],'r');
945-
$xml_data = fread($fp, filesize($_FILES['import_file']['tmp_name']));
946-
fclose($fp);
947-
} else {
948-
header('Location: syslog_alerts.php?header=false');
949-
exit;
950-
}
937+
$xml_data = syslog_get_import_xml_payload('syslog_alerts.php?header=false');
951938

952939
$xml_array = xml2array($xml_data);
953940

syslog_removal.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -731,20 +731,7 @@ function import() {
731731
}
732732

733733
function removal_import() {
734-
$import_text = get_nfilter_request_var('import_text');
735-
736-
if (trim($import_text) != '') {
737-
/* textbox input */
738-
$xml_data = $import_text;
739-
} elseif (($_FILES['import_file']['tmp_name'] != 'none') && ($_FILES['import_file']['tmp_name'] != '')) {
740-
/* file upload */
741-
$fp = fopen($_FILES['import_file']['tmp_name'],'r');
742-
$xml_data = fread($fp, filesize($_FILES['import_file']['tmp_name']));
743-
fclose($fp);
744-
} else {
745-
header('Location: syslog_removal.php?header=false');
746-
exit;
747-
}
734+
$xml_data = syslog_get_import_xml_payload('syslog_removal.php?header=false');
748735

749736
/* obtain debug information if it's set */
750737
$xml_array = xml2array($xml_data);

syslog_reports.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -796,20 +796,7 @@ function import() {
796796
}
797797

798798
function report_import() {
799-
$import_text = get_nfilter_request_var('import_text');
800-
801-
if (trim($import_text) != '') {
802-
/* textbox input */
803-
$xml_data = $import_text;
804-
} elseif (($_FILES['import_file']['tmp_name'] != 'none') && ($_FILES['import_file']['tmp_name'] != '')) {
805-
/* file upload */
806-
$fp = fopen($_FILES['import_file']['tmp_name'],'r');
807-
$xml_data = fread($fp, filesize($_FILES['import_file']['tmp_name']));
808-
fclose($fp);
809-
} else {
810-
header('Location: syslog_reports.php?header=false');
811-
exit;
812-
}
799+
$xml_data = syslog_get_import_xml_payload('syslog_reports.php?header=false');
813800

814801
/* obtain debug information if it's set */
815802
$xml_array = xml2array($xml_data);

0 commit comments

Comments
 (0)