Skip to content

Commit 3f2e226

Browse files
committed
Add checks
Fix #116
1 parent 8ae3bb5 commit 3f2e226

5 files changed

Lines changed: 76 additions & 33 deletions

File tree

‎hook.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ function plugin_addressing_addOrderBy($itemtype, $ID, $order, $key)
476476
{
477477
if ($itemtype == Addressing::class
478478
&& ($ID == 100 || $ID == 101)) {
479-
return "ORDER BY INET_ATON(ITEM_$key) $order";
479+
// $key holds the namespaced itemtype: quote the alias as the SELECT does, or the backslashes break the query
480+
return "ORDER BY INET_ATON(`ITEM_$key`) $order";
480481
}
481482
}
482483

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ parameters:
3636
count: 1
3737
path: src/Addressing.php
3838

39-
-
40-
message: '#^Comparison operation "\>" between 0 and 0 is always false\.$#'
41-
identifier: greater.alwaysFalse
42-
count: 1
43-
path: src/Addressing.php
44-
4539
-
4640
message: '#^Instantiating an object from an unrestricted dynamic string is forbidden \(see https\://github\.com/glpi\-project/phpstan\-glpi\?tab\=readme\-ov\-file\#forbiddynamicinstantiationrule\)\.$#'
4741
identifier: glpi.forbidDynamicInstantiation
@@ -72,12 +66,6 @@ parameters:
7266
count: 1
7367
path: src/Addressing.php
7468

75-
-
76-
message: '#^Result of && is always false\.$#'
77-
identifier: booleanAnd.alwaysFalse
78-
count: 3
79-
path: src/Addressing.php
80-
8169
-
8270
message: '#^Unreachable statement \- code above always terminates\.$#'
8371
identifier: deadCode.unreachable

‎src/Addressing.php‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -975,26 +975,16 @@ public function showReport($params)
975975
{
976976
$Report = new Report();
977977

978-
// Default values of parameters
979-
$default_values["start"] = $start = 0;
980-
$default_values["id"] = $id = 0;
981-
$default_values["export"] = $export = false;
982-
$default_values['filter'] = $filter = 0;
983-
984-
foreach ($default_values as $key => $val) {
985-
if (isset($params[$key])) {
986-
$$key = $params[$key];
987-
}
988-
}
989-
990-
// getFromDB() does not cast its argument, and MySQL coerces a string to a number
991-
// when comparing it to an INT column: "1-alert(1)" would match the row with id 1
992-
// and then reach the template. Force the integer types here, before any use.
993-
// $start is also used in pagination arithmetic, which raises a TypeError in PHP 8
994-
// on a non numeric value and lets a negative offset walk outside the stored range.
995-
$id = (int) $id;
996-
$start = max(0, (int) $start);
997-
$filter = (int) $filter;
978+
// Read each parameter explicitly rather than through a variable-variable loop, which
979+
// turned any key later added to the defaults into a local controlled by the caller
980+
// ($params is $_GET). getFromDB() does not cast its argument, and MySQL coerces a
981+
// string to a number when comparing it to an INT column: "1-alert(1)" would match
982+
// the row with id 1 and then reach the template. $start is also used in pagination
983+
// arithmetic, which raises a TypeError in PHP 8 on a non numeric value and lets a
984+
// negative offset walk outside the stored range.
985+
$id = (int) ($params['id'] ?? 0);
986+
$start = max(0, (int) ($params['start'] ?? 0));
987+
$filter = (int) ($params['filter'] ?? 0);
998988

999989
if (!$this->getFromDB($id)) {
1000990
TemplateRenderer::getInstance()->display('@addressing/report_invalid.html.twig');

‎src/IpComment.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,36 @@ public static function getTypeName($nb = 0)
4343

4444
return _n('IP Addressing', 'IP Addressing', $nb, 'addressing');
4545
}
46+
47+
/*
48+
* The table has no entities_id, so checkEntity() is a no-op and can() would reduce to the
49+
* global plugin_addressing right: the generic front/ipComment.form.php route of the core
50+
* would then read, rewrite or purge the comments of any entity's ranges. Comments are only
51+
* written by ajax/ipcomment.php, which checks the parent range itself and never calls
52+
* can() on this class, so no generic access is granted at all.
53+
*/
54+
public static function canView(): bool
55+
{
56+
return false;
57+
}
58+
59+
public static function canCreate(): bool
60+
{
61+
return false;
62+
}
63+
64+
public static function canUpdate(): bool
65+
{
66+
return false;
67+
}
68+
69+
public static function canDelete(): bool
70+
{
71+
return false;
72+
}
73+
74+
public static function canPurge(): bool
75+
{
76+
return false;
77+
}
4678
}

‎src/PingInfo.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,38 @@ public static function getTypeName($nb = 0)
278278
return _n('IP Addressing', 'IP Addressing', $nb, 'addressing');
279279
}
280280

281+
/*
282+
* The table has no entities_id, so checkEntity() is a no-op and can() would reduce to the
283+
* global plugin_addressing right: the generic front/pingInfo.form.php route of the core
284+
* would then read, rewrite or purge the ping results of any entity's ranges. Rows are only
285+
* written by the cron, ajax/ping.php and Addressing::cleanDBonPurge(), none of which goes
286+
* through can() on this class, so no generic access is granted at all.
287+
*/
288+
public static function canView(): bool
289+
{
290+
return false;
291+
}
292+
293+
public static function canCreate(): bool
294+
{
295+
return false;
296+
}
297+
298+
public static function canUpdate(): bool
299+
{
300+
return false;
301+
}
302+
303+
public static function canDelete(): bool
304+
{
305+
return false;
306+
}
307+
308+
public static function canPurge(): bool
309+
{
310+
return false;
311+
}
312+
281313
/**
282314
* @param $name
283315
**/

0 commit comments

Comments
 (0)