Skip to content

Commit b32c345

Browse files
committed
refactor ajax.php
1 parent b0d0b17 commit b32c345

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

manager/media/style/default/ajax.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
$modx->getSettings();
1212
}
1313

14-
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) {
15-
$modx->sendRedirect($modx->config['site_url']);
14+
if (!isset($_SESSION['mgrValidated']) || !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) {
15+
$modx->sendErrorPage();
1616
}
1717

1818
include_once MODX_BASE_PATH . MGR_DIR . '/includes/lang/' . $modx->config['manager_language'] . '.inc.php';
@@ -197,7 +197,7 @@
197197
$a = 88;
198198
$output = '';
199199
$items = '';
200-
$filter = !empty($_REQUEST['filter']) ? addcslashes(trim($_REQUEST['filter']), '\%*_') : '';
200+
$filter = !empty($_REQUEST['filter']) && is_scalar($_REQUEST['filter']) ? addcslashes(trim($_REQUEST['filter']), '\%*_') : '';
201201
$sqlLike = $filter ? 'WHERE t1.username LIKE "' . $modx->db->escape($filter) . '%"' : '';
202202
$sqlLimit = $sqlLike ? '' : 'LIMIT ' . $limit;
203203

@@ -233,10 +233,11 @@
233233
}
234234

235235
case 'modxTagHelper': {
236-
$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : false;
237-
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : false;
236+
$name = isset($_REQUEST['name']) && is_scalar($_REQUEST['name']) ? $modx->db->escape($_REQUEST['name']) : false;
237+
$type = isset($_REQUEST['type']) && is_scalar($_REQUEST['type']) ? $modx->db->escape($_REQUEST['type']) : false;
238+
$contextmenu = '';
238239

239-
if ($name && $type) {
240+
if ($role && $name && $type) {
240241
switch ($type) {
241242
case 'Snippet':
242243
case 'SnippetNoCache': {
@@ -468,6 +469,8 @@
468469
echo json_encode($contextmenu, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
469470
break;
470471
}
472+
473+
break;
471474
}
472475

473476
case 'movedocument' : {
@@ -476,7 +479,7 @@
476479
if ($modx->hasPermission('new_document') && $modx->hasPermission('edit_document') && $modx->hasPermission('save_document')) {
477480
$id = !empty($_REQUEST['id']) ? (int)$_REQUEST['id'] : '';
478481
$parent = isset($_REQUEST['parent']) ? (int)$_REQUEST['parent'] : 0;
479-
$menuindex = isset($_REQUEST['menuindex']) ? $_REQUEST['menuindex'] : 0;
482+
$menuindex = isset($_REQUEST['menuindex']) && is_scalar($_REQUEST['menuindex']) ? $_REQUEST['menuindex'] : 0;
480483

481484
// set parent
482485
if ($id && $parent >= 0) {

0 commit comments

Comments
 (0)