Skip to content

Commit fd0f2a9

Browse files
committed
Security: Fix SQL injection vulnerability by escaping dates in SOAP registration script
1 parent 06155f1 commit fd0f2a9

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

main/webservices/registration.soap.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,31 +6769,32 @@ function WSCertificatesList($startingDate = '', $endingDate = '')
67696769
$userTable = Database::get_main_table(TABLE_MAIN_USER);
67706770
$categoryTable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
67716771

6772-
$query = "SELECT
6773-
certificate.id,
6774-
user.username,
6775-
category.course_code,
6776-
category.session_id,
6777-
certificate.user_id,
6778-
certificate.cat_id,
6779-
certificate.created_at,
6780-
certificate.path_certificate
6781-
FROM $certificateTable AS certificate
6782-
JOIN $userTable AS user
6783-
ON certificate.user_id = user.user_id
6784-
JOIN $categoryTable AS category
6785-
ON certificate.cat_id = category.id";
6772+
$conditions = [];
67866773

67876774
if (!empty($startingDate) && !empty($endingDate)) {
6788-
$query .= " WHERE certificate.created_at BETWEEN '$startingDate' AND '$endingDate'";
6775+
$conditions['certificate.created_at BETWEEN ? AND ?'] = [$startingDate, $endingDate];
67896776
} elseif (!empty($startingDate)) {
6790-
$query .= " WHERE certificate.created_at >= '$startingDate'";
6777+
$conditions['certificate.created_at >= ?'] = [$startingDate];
67916778
} elseif (!empty($endingDate)) {
6792-
$query .= " WHERE certificate.created_at <= '$endingDate'";
6779+
$conditions['certificate.created_at <= ?'] = [$endingDate];
67936780
}
67946781

6795-
$queryResult = Database::query($query);
6796-
while ($row = Database::fetch_array($queryResult)) {
6782+
$queryResult = Database::select(
6783+
[
6784+
'certificate.id',
6785+
'user.username',
6786+
'category.course_code',
6787+
'category.session_id',
6788+
'certificate.user_id',
6789+
'certificate.cat_id',
6790+
'certificate.created_at',
6791+
'certificate.path_certificate',
6792+
],
6793+
$certificateTable,
6794+
['where' => $conditions]
6795+
);
6796+
6797+
foreach ($queryResult as $row) {
67976798
$userPath = USermanager::getUserPathById($row['user_id'], 'web');
67986799
$row['path_certificate'] = $userPath.'/certificate'.$row['path_certificate'];
67996800
$result[] = $row;

0 commit comments

Comments
 (0)