Skip to content

Commit 34c3357

Browse files
Security: Reduce XSS/CSRF probability as admin user - refs BT#21289
Author: 84335353+christianbeeznest@users.noreply.github.com
1 parent 67076c4 commit 34c3357

6 files changed

+36
-27
lines changed

Diff for: main/admin/add_courses_to_usergroup.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function remove_item(origin) {
4646

4747
$errorMsg = '';
4848
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
49-
$form_sent = $_POST['form_sent'];
50-
$elements_posted = $_POST['elements_in_name'];
49+
$form_sent = (int) $_POST['form_sent'];
50+
$elements_posted = Security::remove_XSS($_POST['elements_in_name']);
5151
if (!is_array($elements_posted)) {
5252
$elements_posted = [];
5353
}
@@ -187,7 +187,7 @@ function search($needle, $type)
187187
$searchForm->display();
188188
echo '</div>';
189189
?>
190-
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($_GET['add'])) {
190+
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($add)) {
191191
echo '&add=true';
192192
} ?>" style="margin:0px;" <?php if ($ajax_search) {
193193
echo ' onsubmit="valide();"';

Diff for: main/admin/add_sessions_to_usergroup.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function validate_filter() {
7373

7474
$errorMsg = '';
7575
if (isset($_POST['form_sent']) && $_POST['form_sent']) {
76-
$form_sent = $_POST['form_sent'];
77-
$elements_posted = $_POST['elements_in_name'];
76+
$form_sent = (int) $_POST['form_sent'];
77+
$elements_posted = Security::remove_XSS($_POST['elements_in_name']);
7878
if (!is_array($elements_posted)) {
7979
$elements_posted = [];
8080
}
@@ -168,7 +168,7 @@ function search_usergroup_sessions($needle, $type)
168168
echo '<div id="advancedSearch" style="display: none">'.get_lang('SearchSessions'); ?> :
169169
<input name="SearchSession" onchange = "xajax_search_usergroup_sessions(this.value,'searchbox')" onkeyup="this.onchange()">
170170
</div>
171-
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($_GET['add'])) {
171+
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($add)) {
172172
echo '&add=true';
173173
} ?>" style="margin:0px;" <?php if ($ajax_search) {
174174
echo ' onsubmit="valide();"';

Diff for: main/admin/dashboard_add_sessions_to_user.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
3030

3131
// Initializing variables
32-
$user_id = isset($_GET['user']) ? intval($_GET['user']) : null;
32+
$user_id = isset($_GET['user']) ? (int) $_GET['user'] : null;
3333
$user_info = api_get_user_info($user_id);
3434
$user_anonymous = api_get_anonymous_id();
3535
$current_user_id = api_get_user_id();
@@ -72,10 +72,10 @@ function search_sessions($needle, $type)
7272

7373
if (api_is_multiple_url_enabled()) {
7474
$sql = " SELECT s.id, s.name FROM $tbl_session s
75-
LEFT JOIN $tbl_session_rel_access_url a
75+
LEFT JOIN $tbl_session_rel_access_url a
7676
ON (s.id = a.session_id)
77-
WHERE
78-
s.name LIKE '$needle%' $without_assigned_sessions AND
77+
WHERE
78+
s.name LIKE '$needle%' $without_assigned_sessions AND
7979
access_url_id = ".api_get_current_access_url_id();
8080
} else {
8181
$sql = "SELECT s.id, s.name FROM $tbl_session s
@@ -150,12 +150,12 @@ function remove_item(origin) {
150150
</script>';
151151

152152
$formSent = 0;
153-
$firstLetterSession = isset($_POST['firstLetterSession']) ? $_POST['firstLetterSession'] : null;
153+
$firstLetterSession = isset($_POST['firstLetterSession']) ? Security::remove_XSS($_POST['firstLetterSession']) : null;
154154
$errorMsg = '';
155155
$UserList = [];
156156

157-
if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
158-
$sessions_list = $_POST['SessionsList'];
157+
if (isset($_POST['formSent']) && 1 == (int) $_POST['formSent']) {
158+
$sessions_list = Security::remove_XSS($_POST['SessionsList']);
159159
$userInfo = api_get_user_info($user_id);
160160
$affected_rows = SessionManager::subscribeSessionsToDrh(
161161
$userInfo,

Diff for: main/admin/dashboard_add_users_to_user.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
$userStatus = api_get_user_status($user_id);
3939

40-
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
40+
$firstLetterUser = isset($_POST['firstLetterUser']) ? Security::remove_XSS($_POST['firstLetterUser']) : null;
4141

4242
// setting the name of the tool
4343
$isAdmin = UserManager::is_admin($user_id);
@@ -287,7 +287,7 @@ function remove_item(origin) {
287287
}
288288

289289
if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
290-
$user_list = isset($_POST['UsersList']) ? $_POST['UsersList'] : null;
290+
$user_list = isset($_POST['UsersList']) ? Security::remove_XSS($_POST['UsersList']) : null;
291291
switch ($userStatus) {
292292
case DRH:
293293
case PLATFORM_ADMIN:

Diff for: main/auth/sort_my_courses.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$user_course_categories = CourseManager::get_user_course_categories(api_get_user_id());
1313
$courses_in_category = $auth->getCoursesInCategory(false);
1414

15-
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
15+
$action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : '';
1616
$currentUrl = api_get_self();
1717

1818
$interbreadcrumb[] = [
@@ -22,7 +22,9 @@
2222

2323
// We are moving the course of the user to a different user defined course category (=Sort My Courses).
2424
if (isset($_POST['submit_change_course_category'])) {
25-
$result = $auth->updateCourseCategory($_POST['course_2_edit_category'], $_POST['course_categories']);
25+
$course2EditCategory = Security::remove_XSS($_POST['course_2_edit_category']);
26+
$courseCategories = Security::remove_XSS($_POST['course_categories']);
27+
$result = $auth->updateCourseCategory($course2EditCategory, $courseCategories);
2628
if ($result) {
2729
Display::addFlash(
2830
Display::return_message(get_lang('EditCourseCategorySucces'))
@@ -36,7 +38,9 @@
3638
if (isset($_POST['submit_edit_course_category']) &&
3739
isset($_POST['title_course_category'])
3840
) {
39-
$result = $auth->store_edit_course_category($_POST['title_course_category'], $_POST['category_id']);
41+
$titleCourseCategory = Security::remove_XSS($_POST['title_course_category']);
42+
$categoryId = Security::remove_XSS($_POST['category_id']);
43+
$result = $auth->store_edit_course_category($titleCourseCategory, $categoryId);
4044
if ($result) {
4145
Display::addFlash(
4246
Display::return_message(get_lang('CourseCategoryEditStored'))
@@ -52,7 +56,8 @@
5256
isset($_POST['title_course_category']) &&
5357
strlen(trim($_POST['title_course_category'])) > 0
5458
) {
55-
$result = $auth->store_course_category($_POST['title_course_category']);
59+
$titleCourseCategory = Security::remove_XSS($_POST['title_course_category']);
60+
$result = $auth->store_course_category($titleCourseCategory);
5661
if ($result) {
5762
Display::addFlash(
5863
Display::return_message(get_lang('CourseCategoryStored'))
@@ -71,16 +76,19 @@
7176

7277
// We are moving a course or category of the user up/down the list (=Sort My Courses).
7378
if (isset($_GET['move'])) {
74-
if (isset($_GET['course'])) {
75-
$result = $auth->move_course($_GET['move'], $_GET['course'], $_GET['category']);
79+
$getCourse = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : '';
80+
$getMove = Security::remove_XSS($_GET['move']);
81+
$getCategory = isset($_GET['category']) ? Security::remove_XSS($_GET['category']) : '';
82+
if (!empty($getCourse)) {
83+
$result = $auth->move_course($getMove, $getCourse, $getCategory);
7684
if ($result) {
7785
Display::addFlash(
7886
Display::return_message(get_lang('CourseSortingDone'))
7987
);
8088
}
8189
}
82-
if (isset($_GET['category']) && !isset($_GET['course'])) {
83-
$result = $auth->move_category($_GET['move'], $_GET['category']);
90+
if (!empty($getCategory) && empty($getCourse)) {
91+
$result = $auth->move_category($getMove, $getCategory);
8492
if ($result) {
8593
Display::addFlash(
8694
Display::return_message(get_lang('CategorySortingDone'))
@@ -152,7 +160,8 @@
152160
// we are deleting a course category
153161
if (isset($_GET['id'])) {
154162
if (Security::check_token('get')) {
155-
$result = $auth->delete_course_category($_GET['id']);
163+
$getId = Security::remove_XSS($_GET['id']);
164+
$result = $auth->delete_course_category($getId);
156165
if ($result) {
157166
Display::addFlash(
158167
Display::return_message(get_lang('CourseCategoryDeleted'))
@@ -182,7 +191,7 @@
182191
$userId = api_get_user_id();
183192
$categoryId = isset($_REQUEST['categoryid']) ? (int) $_REQUEST['categoryid'] : 0;
184193
$option = isset($_REQUEST['option']) ? (int) $_REQUEST['option'] : 0;
185-
$redirect = isset($_REQUEST['redirect']) ? $_REQUEST['redirect'] : 0;
194+
$redirect = isset($_REQUEST['redirect']) ? Security::remove_XSS($_REQUEST['redirect']) : 0;
186195

187196
if (empty($userId) || empty($categoryId)) {
188197
api_not_allowed(true);

Diff for: main/session/session_add.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function emptyDuration() {
115115
}
116116
</script>";
117117

118-
if (isset($_POST['formSent']) && $_POST['formSent']) {
119-
$formSent = 1;
118+
if (isset($_POST['formSent'])) {
119+
$formSent = (int) $_POST['formSent'];
120120
}
121121

122122
$tool_name = get_lang('AddSession');

0 commit comments

Comments
 (0)