Skip to content

Commit 69aa7b3

Browse files
committed
Add security checks
1 parent 7ae1b7a commit 69aa7b3

6 files changed

Lines changed: 31 additions & 31 deletions

File tree

ajax/addressing.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
header("Content-Type: text/html; charset=UTF-8");
4040

4141
if (isset($_GET['action']) && $_GET['action'] == 'isName') {
42-
$item = new $_GET['type']();
43-
$datas = $item->find(['name' => ['LIKE', $_GET['name']]]);
44-
if (count($datas) > 0) {
45-
echo json_encode(true);
46-
} else {
42+
header("Content-Type: application/json; charset=UTF-8");
43+
$item = getItemForItemtype($_GET['type'] ?? '');
44+
if ($item === false) {
4745
echo json_encode(false);
46+
} else {
47+
$datas = $item->find(['name' => ['LIKE', $_GET['name']]]);
48+
echo json_encode(count($datas) > 0);
4849
}
4950
} else if (isset($_POST['action']) && $_POST['action'] == 'viewFilter') {
5051
if (isset($_POST['items_id'])

front/report.form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
$USEDBREPLICATE = 1;
3434
$DBCONNECTION_REQUIRED = 0;
3535

36-
Html::header(Addressing::getTypeName(2), '', "tools", Addressing::class);
37-
3836
Session::checkLoginUser();
3937

38+
Html::header(Addressing::getTypeName(2), '', "tools", Addressing::class);
39+
4040
if (!isset($_GET["start"])) {
4141
$_GET["start"] = 0;
4242
}

hook.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
--------------------------------------------------------------------------
2828
*/
2929

30+
use Glpi\Plugin\Hooks;
3031
use GlpiPlugin\Addressing\Addressing;
3132
use GlpiPlugin\Addressing\Filter;
3233
use GlpiPlugin\Addressing\PingInfo;
@@ -396,10 +397,10 @@ function plugin_addressing_postinit()
396397
{
397398
global $PLUGIN_HOOKS;
398399

399-
$PLUGIN_HOOKS['item_purge']['addressing'] = [];
400+
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['addressing'] = [];
400401

401402
foreach (Addressing::getTypes() as $type) {
402-
$PLUGIN_HOOKS['item_purge']['addressing'][$type]
403+
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['addressing'][$type]
403404
= [PingInfo::class, 'cleanForItem'];
404405
}
405406
}

setup.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ function plugin_init_addressing()
4949
{
5050
global $PLUGIN_HOOKS;
5151

52-
$PLUGIN_HOOKS['csrf_compliant']['addressing'] = true;
53-
54-
$PLUGIN_HOOKS['change_profile']['addressing'] = [Profile::class, 'initProfile'];
52+
$PLUGIN_HOOKS[Hooks::CHANGE_PROFILE]['addressing'] = [Profile::class, 'initProfile'];
5553

5654
Plugin::registerClass(
5755
Profile::class,
@@ -60,19 +58,19 @@ function plugin_init_addressing()
6058

6159
if (Session::getLoginUserID()) {
6260
if (Session::haveRight('plugin_addressing', READ)) {
63-
$PLUGIN_HOOKS["menu_toadd"]['addressing'] = ['tools' => Addressing::class];
61+
$PLUGIN_HOOKS[Hooks::MENU_TOADD]['addressing'] = ['tools' => Addressing::class];
6462
}
6563

6664
if (Session::haveRight('plugin_addressing', UPDATE)) {
67-
$PLUGIN_HOOKS['use_massive_action']['addressing'] = 1;
65+
$PLUGIN_HOOKS[Hooks::USE_MASSIVE_ACTION]['addressing'] = 1;
6866
}
6967

7068
// Config page
7169
if (Session::haveRight("config", UPDATE)) {
72-
$PLUGIN_HOOKS['config_page']['addressing'] = 'front/config.php';
70+
$PLUGIN_HOOKS[Hooks::CONFIG_PAGE]['addressing'] = 'front/config.php';
7371
}
7472

75-
$PLUGIN_HOOKS['post_item_form']['addressing'] = [PingInfo::class,
73+
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['addressing'] = [PingInfo::class,
7674
'getPingResponseForItem'];
7775

7876
// Add specific files to add to the header : javascript or css

src/Ping_Equipment.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ public function ping($system, $ip, $return = "list")
161161
case 0:
162162
// linux ping
163163
if ($return == "true") {
164-
exec("ping -c 1 -w 1 " . $ip, $list);
164+
exec("ping -c 1 -w 1 " . escapeshellarg($ip), $list);
165165
} else {
166-
exec("ping -c 1 -w 1 " . $ip, $list, $error);
166+
exec("ping -c 1 -w 1 " . escapeshellarg($ip), $list, $error);
167167
}
168168
$nb = count($list);
169169
if (isset($nb) && $return == "true") {
@@ -178,9 +178,9 @@ public function ping($system, $ip, $return = "list")
178178
case 1:
179179
//windows
180180
if ($return == "true") {
181-
exec("ping.exe -n 1 -w 100 -i 64 " . $ip, $list);
181+
exec("ping.exe -n 1 -w 100 -i 64 " . escapeshellarg($ip), $list);
182182
} else {
183-
exec("ping.exe -n 1 -w 100 -i 64 " . $ip, $list, $error);
183+
exec("ping.exe -n 1 -w 100 -i 64 " . escapeshellarg($ip), $list, $error);
184184
}
185185
$nb = count($list);
186186
if (isset($nb) && $return == "true") {
@@ -195,9 +195,9 @@ public function ping($system, $ip, $return = "list")
195195
case 2:
196196
//linux fping
197197
if ($return == "true") {
198-
exec("fping -r1 -c1 -t100 " . $ip, $list);
198+
exec("fping -r1 -c1 -t100 " . escapeshellarg($ip), $list);
199199
} else {
200-
exec("fping -r1 -c1 -t100 " . $ip, $list, $error);
200+
exec("fping -r1 -c1 -t100 " . escapeshellarg($ip), $list, $error);
201201
}
202202
$nb = count($list);
203203
if (isset($nb) && $return == "true") {
@@ -212,9 +212,9 @@ public function ping($system, $ip, $return = "list")
212212
case 3:
213213
// BSD ping
214214
if ($return == "true") {
215-
exec("ping -c 1 -W 1 " . $ip, $list);
215+
exec("ping -c 1 -W 1 " . escapeshellarg($ip), $list);
216216
} else {
217-
exec("ping -c 1 -W 1 " . $ip, $list, $error);
217+
exec("ping -c 1 -W 1 " . escapeshellarg($ip), $list, $error);
218218
}
219219
$nb = count($list);
220220
if (isset($nb) && $return == "true") {
@@ -229,9 +229,9 @@ public function ping($system, $ip, $return = "list")
229229
case 4:
230230
// MacOSX ping
231231
if ($return == "true") {
232-
exec("ping -c 1 -t 1 " . $ip, $list);
232+
exec("ping -c 1 -t 1 " . escapeshellarg($ip), $list);
233233
} else {
234-
exec("ping -c 1 -t 1 " . $ip, $list, $error);
234+
exec("ping -c 1 -t 1 " . escapeshellarg($ip), $list, $error);
235235
}
236236
$nb = count($list);
237237
if (isset($nb) && $return == "true") {
@@ -265,12 +265,12 @@ public function getHostnameByPing($system, $ip)
265265
switch ($system) {
266266
case 0:
267267
// linux host
268-
exec("ping -c 1 -w 1 -a " . $ip, $list, $error);
268+
exec("ping -c 1 -w 1 -a " . escapeshellarg($ip), $list, $error);
269269
break;
270270

271271
case 1:
272272
//windows
273-
exec("ping.exe -n 1 -w 100 -i 64 -a " . $ip, $list, $error);
273+
exec("ping.exe -n 1 -w 100 -i 64 -a " . escapeshellarg($ip), $list, $error);
274274
break;
275275
}
276276
$list_str = implode('<br />', $list);

src/Report.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public function displayReport(&$result, $Addressing, $values, $ping_status = [])
628628
if ($is_html_output) {
629629
$html_output .= $output::showItem(
630630
'<input type="text" id="comment' . $num . '"
631-
value="' . $comments . '">',
631+
value="' . htmlspecialchars($comments, ENT_QUOTES, 'UTF-8') . '">',
632632
$item_num,
633633
$row_num,
634634
"style='background-color:#e0e0e0' class='center' onChange='updateFA$rand()'"
@@ -807,7 +807,7 @@ function updateFA$rand() {
807807
if ($is_html_output) {
808808
$html_output .= $output::showItem(
809809
'<input type="text" id="comment' . $num . '"
810-
value="' . $comments . '">',
810+
value="' . htmlspecialchars($comments, ENT_QUOTES, 'UTF-8') . '">',
811811
$item_num,
812812
$row_num,
813813
"style='background-color:#e0e0e0' class='center' onChange='updateFA$rand()'"
@@ -1203,7 +1203,7 @@ function updateFA$rand() {
12031203
if ($is_html_output) {
12041204
$html_output .= $output::showItem(
12051205
'<input type="text" id="comment' . $num . '"
1206-
value="' . $comments . '">',
1206+
value="' . htmlspecialchars($comments, ENT_QUOTES, 'UTF-8') . '">',
12071207
$item_num,
12081208
$row_num,
12091209
"style='background-color:#e0e0e0' class='center' onChange='updateFA$rand()'"

0 commit comments

Comments
 (0)