Skip to content

Commit dd33807

Browse files
committed
Disable web service WSEditUserWithPicture if allow_url_fopen = true
Check that upload file is an image.
1 parent 9fb379c commit dd33807

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

main/inc/lib/usermanager.lib.php

+9
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,15 @@ public static function update_user_picture(
25982598
$filename = $user_id.'_'.$filename;
25992599
}
26002600

2601+
if (!file_exists($source_file)) {
2602+
return false;
2603+
}
2604+
2605+
$mimeContentType = mime_content_type($source_file);
2606+
if (false === strpos($mimeContentType, 'image')) {
2607+
return false;
2608+
}
2609+
26012610
//Crop the image to adjust 1:1 ratio
26022611
$image = new Image($source_file);
26032612
$image->crop($cropParameters);

main/webservices/registration.soap.php

+34-22
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ function WSCreateUsersPasswordCrypted($params)
867867
$count_row = Database::num_rows($res);
868868
if ($count_row > 0) {
869869
// Check if user is not active.
870-
$sql = "SELECT user_id FROM $table_user
870+
$sql = "SELECT user_id FROM $table_user
871871
WHERE user_id ='".$row[1]."' AND active= '0'";
872872
$resu = Database::query($sql);
873873
$r_check_user = Database::fetch_row($resu);
@@ -1389,7 +1389,7 @@ function WSCreateUserPasswordCrypted($params)
13891389
phone='".Database::escape_string($phone)."',
13901390
expiration_date='".Database::escape_string($expiration_date)."',
13911391
active='1',
1392-
hr_dept_id=".intval($hr_dept_id)."
1392+
hr_dept_id=".intval($hr_dept_id)."
13931393
WHERE user_id='".$r_check_user[0]."'";
13941394

13951395
Database::query($sql);
@@ -1459,7 +1459,7 @@ function WSCreateUserPasswordCrypted($params)
14591459
phone = '".Database::escape_string($phone)."',
14601460
language = '".Database::escape_string($language)."',
14611461
registration_date = '".api_get_utc_datetime()."',
1462-
roles = 'a:0:{}',
1462+
roles = 'a:0:{}',
14631463
".$queryExpirationDate."
14641464
hr_dept_id = '".Database::escape_string($hr_dept_id)."',
14651465
active = '".Database::escape_string($active)."'";
@@ -2078,13 +2078,20 @@ function WSEditUser($params)
20782078
// Define the method WSEditUserWithPicture
20792079
function WSEditUserWithPicture($params)
20802080
{
2081+
if (ini_get('allow_url_fopen')) {
2082+
return new soap_fault(
2083+
'Server',
2084+
'',
2085+
'WSEditUserWithPicture is disabled because allow_url_fopen is enabled in the server.'
2086+
);
2087+
}
2088+
20812089
if (!WSHelperVerifyKey($params)) {
20822090
return returnError(WS_ERROR_SECRET_KEY);
20832091
}
20842092

20852093
$userManager = UserManager::getManager();
20862094
$userRepository = UserManager::getRepository();
2087-
20882095
$table_user = Database::get_main_table(TABLE_MAIN_USER);
20892096

20902097
$original_user_id_value = $params['original_user_id_value'];
@@ -2118,28 +2125,19 @@ function WSEditUserWithPicture($params)
21182125
$original_user_id_name
21192126
);
21202127

2121-
// Get picture and generate uri.
2122-
$filename = basename($picture_url);
2123-
$tempDir = api_get_path(SYS_ARCHIVE_PATH);
2124-
// Make sure the file download was OK by checking the HTTP headers for OK
2125-
if (strpos(get_headers($picture_url)[0], "OK")) {
2126-
file_put_contents($tempDir.$filename, file_get_contents($picture_url));
2127-
$pictureUri = UserManager::update_user_picture($user_id, $filename, $tempDir.$filename);
2128+
if (empty($user_id)) {
2129+
return 0;
21282130
}
21292131

2130-
if ($user_id == 0) {
2132+
$sql = "SELECT id FROM $table_user WHERE id =$user_id AND active= 0";
2133+
$resu = Database::query($sql);
2134+
$r_check_user = Database::fetch_row($resu);
2135+
if (!empty($r_check_user[0])) {
21312136
return 0;
2132-
} else {
2133-
$sql = "SELECT id FROM $table_user WHERE id =$user_id AND active= 0";
2134-
$resu = Database::query($sql);
2135-
$r_check_user = Database::fetch_row($resu);
2136-
if (!empty($r_check_user[0])) {
2137-
return 0;
2138-
}
21392137
}
21402138

21412139
// Check whether username already exits.
2142-
$sql = "SELECT username FROM $table_user
2140+
$sql = "SELECT username FROM $table_user
21432141
WHERE username = '$username' AND id <> $user_id";
21442142
$res_un = Database::query($sql);
21452143
$r_username = Database::fetch_row($res_un);
@@ -2148,6 +2146,19 @@ function WSEditUserWithPicture($params)
21482146
return 0;
21492147
}
21502148

2149+
// Get picture and generate uri.
2150+
$filename = basename($picture_url);
2151+
$tempDir = api_get_path(SYS_ARCHIVE_PATH);
2152+
// Make sure the file download was OK by checking the HTTP headers for OK
2153+
if (strpos(get_headers($picture_url)[0], "OK")) {
2154+
$tempFile = $tempDir.uniqid('user_image', true);
2155+
file_put_contents($tempFile, file_get_contents($picture_url));
2156+
$pictureUri = UserManager::update_user_picture($user_id, $filename, $tempFile);
2157+
if (file_exists($tempFile)) {
2158+
unlink($tempFile);
2159+
}
2160+
}
2161+
21512162
/** @var User $user */
21522163
$user = $userRepository->find($user_id);
21532164

@@ -2190,7 +2201,8 @@ function WSEditUserWithPicture($params)
21902201
->setExpirationDate($expiration_date)
21912202
->setHrDeptId($hr_dept_id)
21922203
->setActive(true)
2193-
->setPictureUri($pictureUri);
2204+
->setPictureUri($pictureUri)
2205+
;
21942206

21952207
if (!is_null($creator_id)) {
21962208
$user->setCreatorId($creator_id);
@@ -4768,7 +4780,7 @@ function WSSubscribeUserToCourseSimple($params)
47684780
error_log('Try to register: user_id= '.$user_id.' to course: '.$course_data['code']);
47694781
}
47704782
if (!CourseManager::subscribeUser($user_id, $course_data['code'], $status, 0, false, false)) {
4771-
$result = 'User was not registered possible reasons: User already registered to the course,
4783+
$result = 'User was not registered possible reasons: User already registered to the course,
47724784
Course visibility doesnt allow user subscriptions ';
47734785
if ($debug) {
47744786
error_log($result);

0 commit comments

Comments
 (0)