Skip to content

Commit 87d92a1

Browse files
somethingwithproofTheWitnessCopilot
authored
fix(security): defense-in-depth hardening for plugin_mactrack (#325)
* fix(security): defense-in-depth hardening for plugin_mactrack 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> * fix(js): migrate deprecated jQuery shorthand events to .on()/.off() Replace .click(fn) with .on('click', fn), .change(fn) with .on('change', fn), .submit(fn) with .on('submit', fn), .unbind() with .off(), and .resize(fn) with .on('resize', fn). These shorthands were deprecated in jQuery 3.3 and will be removed in jQuery 4.0. Cacti core ships jQuery 3.x on develop. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(ci): Dependabot composer ecosystem, CodeQL PHP coverage - Change Dependabot ecosystem from npm to composer (PHP-only repo) - Remove PHP from CodeQL paths-ignore so security PRs get analysis - Remove committed .omc session artifacts, add .omc/ to .gitignore Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * Update mactrack_view_macs.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: Running php-cs-fixit on code --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: TheWitness <thewitness@cacti.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4c5d0a8 commit 87d92a1

18 files changed

Lines changed: 53 additions & 52 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
# +-------------------------------------------------------------------------+
2121

2222
locales/po/*.mo
23+
.omc/

Net/DNS2/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function get($key) {
6767
if ($this->cache_serializer == 'json') {
6868
return json_decode($this->cache_data[$key]['object']);
6969
} else {
70-
return unserialize($this->cache_data[$key]['object']);
70+
return unserialize($this->cache_data[$key]['object'], ['allowed_classes' => false]);
7171
}
7272
} else {
7373
return false;

Net/DNS2/Cache/File.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function open($cache_file, $size, $serializer) {
6767
if ($this->cache_serializer == 'json') {
6868
$decoded = json_decode($data, true);
6969
} else {
70-
$decoded = unserialize($data);
70+
$decoded = unserialize($data, ['allowed_classes' => false]);
7171
}
7272

7373
if (is_array($decoded) == true) {
@@ -145,7 +145,7 @@ public function __destruct() {
145145
if ($this->cache_serializer == 'json') {
146146
$decoded = json_decode($data, true);
147147
} else {
148-
$decoded = unserialize($data);
148+
$decoded = unserialize($data, ['allowed_classes' => false]);
149149
}
150150

151151
if (is_array($decoded) == true) {

Net/DNS2/Cache/Shm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function open($cache_file, $size, $serializer) {
104104
if ($this->cache_serializer == 'json') {
105105
$decoded = json_decode($data, true);
106106
} else {
107-
$decoded = unserialize($data);
107+
$decoded = unserialize($data, ['allowed_classes' => false]);
108108
}
109109

110110
if (is_array($decoded) == true) {
@@ -195,7 +195,7 @@ public function __destruct() {
195195
if ($this->cache_serializer == 'json') {
196196
$decoded = json_decode($data, true);
197197
} else {
198-
$decoded = unserialize($data);
198+
$decoded = unserialize($data, ['allowed_classes' => false]);
199199
}
200200

201201
if (is_array($decoded) == true) {

lib/mactrack_functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,16 +3713,16 @@ function exportRows() {
37133713
}
37143714

37153715
$(function() {
3716-
$('#mactrack').submit(function(event) {
3716+
$('#mactrack').on('submit', function(event) {
37173717
event.preventDefault();
37183718
applyFilter();
37193719
});
37203720

3721-
$('#clear').click(function() {
3721+
$('#clear').on('click', function() {
37223722
clearFilter();
37233723
});
37243724

3725-
$('#export').click(function() {
3725+
$('#export').on('click', function() {
37263726
exportRows();
37273727
});
37283728

mactrack_device_types.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,24 +1180,24 @@ function scanDeviceType() {
11801180
}
11811181

11821182
$(function() {
1183-
$('#mactrack').submit(function(event) {
1183+
$('#mactrack').on('submit', function(event) {
11841184
event.preventDefault();
11851185
applyFilter();
11861186
});
11871187

1188-
$('#clear').click(function() {
1188+
$('#clear').on('click', function() {
11891189
clearFilter();
11901190
});
11911191

1192-
$('#export').click(function() {
1192+
$('#export').on('click', function() {
11931193
exportRows();
11941194
});
11951195

1196-
$('#import').click(function() {
1196+
$('#import').on('click', function() {
11971197
importRows();
11981198
});
11991199

1200-
$('#scan').click(function() {
1200+
$('#scan').on('click', function() {
12011201
scanDeviceType();
12021202
});
12031203
});

mactrack_devices.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,20 +1315,20 @@ function importRows() {
13151315
}
13161316

13171317
$(function() {
1318-
$('#mactrack').submit(function(event) {
1318+
$('#mactrack').on('submit', function(event) {
13191319
event.preventDefault();
13201320
applyFilter();
13211321
});
13221322

1323-
$('#clear').click(function() {
1323+
$('#clear').on('click', function() {
13241324
clearFilter();
13251325
});
13261326

1327-
$('#export').click(function() {
1327+
$('#export').on('click', function() {
13281328
exportRows();
13291329
});
13301330

1331-
$('#import').click(function() {
1331+
$('#import').on('click', function() {
13321332
importRows();
13331333
});
13341334
});

mactrack_macauth.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function mactrack_maca_filter() {
407407
</td>
408408
</tr>
409409
</table>
410-
<input type='hidden' id='page' value='<?php print get_request_var('page'); ?>'>
410+
<input type='hidden' id='page' value='<?php print html_escape_request_var('page'); ?>'>
411411
</form>
412412
<script type='text/javascript'>
413413

@@ -424,12 +424,12 @@ function clearFilter() {
424424
}
425425

426426
$(function() {
427-
$('#mactrack').submit(function(event) {
427+
$('#mactrack').on('submit', function(event) {
428428
event.preventDefault();
429429
applyFilter();
430430
});
431431

432-
$('#clear').click(function() {
432+
$('#clear').on('click', function() {
433433
clearFilter();
434434
});
435435
});

mactrack_macwatch.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function mactrack_macw_filter() {
415415
</td>
416416
</tr>
417417
</table>
418-
<input type='hidden' id='page' value='<?php print get_request_var('page'); ?>'>
418+
<input type='hidden' id='page' value='<?php print html_escape_request_var('page'); ?>'>
419419
</form>
420420
<script type='text/javascript'>
421421

@@ -432,12 +432,12 @@ function clearFilter() {
432432
}
433433

434434
$(function() {
435-
$('#mactrack').submit(function(event) {
435+
$('#mactrack').on('submit', function(event) {
436436
event.preventDefault();
437437
applyFilter();
438438
});
439439

440-
$('#clear').click(function() {
440+
$('#clear').on('click', function() {
441441
clearFilter();
442442
});
443443
});

mactrack_snmp.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ function mactrack_snmp_item_edit() {
373373
<script type='text/javascript'>
374374
$(function() {
375375
setSNMP();
376-
$('#snmp_version').change(function() {
376+
$('#snmp_version').on('change', function() {
377377
setSNMP();
378378
});
379379
});
@@ -635,7 +635,7 @@ function snmp_options_filter() {
635635
</td>
636636
</tr>
637637
</table>
638-
<input type='hidden' name='page' value='<?php print get_request_var('page'); ?>'>
638+
<input type='hidden' name='page' value='<?php print html_escape_request_var('page'); ?>'>
639639
</td>
640640
</form>
641641
<script type='text/javascript'>
@@ -653,15 +653,15 @@ function clearFilter() {
653653
}
654654

655655
$(function() {
656-
$('#go').click(function() {
656+
$('#go').on('click', function() {
657657
applyFilter();
658658
});
659659

660-
$('#clear').click(function() {
660+
$('#clear').on('click', function() {
661661
clearFilter();
662662
});
663663

664-
$('#mactrack_snmp').unbind().submit(function(event) {
664+
$('#mactrack_snmp').off().on('submit', function(event) {
665665
event.preventDefault();
666666
applyFilter();
667667
});

0 commit comments

Comments
 (0)