Skip to content

Commit ba7e15d

Browse files
committed
Security: Fix case sensitivity in phar file validation
Adjusted the `str_starts_with` checks to be case-insensitive by converting paths to lowercase. Also refactored the logic to separate `isPharFile` handling from writable checks, improving readability and error handling with better feedback messages.
1 parent ef2d805 commit ba7e15d

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

plugin/vchamilo/views/import.php

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -131,54 +131,63 @@
131131
$confFile = $values['configuration_file'];
132132
$uploadPath = $values['upload_path'];
133133

134-
$isPharFile = str_starts_with($confFile, 'phar://')
135-
|| str_starts_with($coursePath, 'phar://')
136-
|| str_starts_with($homePath, 'phar://')
137-
|| str_starts_with($uploadPath, 'phar://');
138-
139-
$isWritable = is_dir($coursePath)
140-
&& is_dir($homePath)
141-
&& is_dir($uploadPath)
142-
&& file_exists($confFile)
143-
&& is_readable($confFile);
144-
145-
if (!$isPharFile && $isWritable) {
146-
$currentHost = api_get_configuration_value('db_host');
147-
$currentDatabase = api_get_configuration_value('main_database');
148-
$currentUser = api_get_configuration_value('db_user');
149-
$currentPassword = api_get_configuration_value('db_password');
150-
151-
if ($values['to_main_database'] !== $currentDatabase &&
152-
$values['to_db_user'] !== $currentUser &&
153-
$values['to_db_password'] !== $currentPassword
154-
) {
155-
} else {
156-
Display::addFlash(
157-
Display::return_message(
158-
$plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo'),
159-
'warning'
160-
)
161-
);
134+
$isPharFile = str_starts_with(strtolower($confFile), 'phar://')
135+
|| str_starts_with(strtolower($coursePath), 'phar://')
136+
|| str_starts_with(strtolower($homePath), 'phar://')
137+
|| str_starts_with(strtolower($uploadPath), 'phar://');
138+
139+
if ($isPharFile) {
140+
Display::addFlash(
141+
Display::return_message(
142+
$plugin->get_lang('NotAllowed'),
143+
'error'
144+
)
145+
);
146+
} else {
147+
$isWritable = is_dir($coursePath)
148+
&& is_dir($homePath)
149+
&& is_dir($uploadPath)
150+
&& file_exists($confFile)
151+
&& is_readable($confFile);
152+
153+
if ($isWritable) {
154+
$currentHost = api_get_configuration_value('db_host');
155+
$currentDatabase = api_get_configuration_value('main_database');
156+
$currentUser = api_get_configuration_value('db_user');
157+
$currentPassword = api_get_configuration_value('db_password');
158+
159+
if ($values['to_main_database'] !== $currentDatabase &&
160+
$values['to_db_user'] !== $currentUser &&
161+
$values['to_db_password'] !== $currentPassword
162+
) {
163+
} else {
164+
Display::addFlash(
165+
Display::return_message(
166+
$plugin->get_lang('DatabaseAccessShouldBeDifferentThanMasterChamilo'),
167+
'warning'
168+
)
169+
);
170+
}
171+
172+
$vchamilo = new stdClass();
173+
$vchamilo->main_database = $values['main_database'];
174+
$vchamilo->db_user = $values['db_user'];
175+
$vchamilo->db_password = $values['db_password'];
176+
$vchamilo->db_host = $values['db_host'];
177+
$vchamilo->root_web = $values['root_web'];
178+
$vchamilo->import_to_main_database = $values['to_main_database'];
179+
$vchamilo->import_to_db_user = $values['to_db_user'];
180+
$vchamilo->import_to_db_password = $values['to_db_password'];
181+
$vchamilo->import_to_db_host = $values['to_db_host'];
182+
$vchamilo->course_path = $values['course_path'];
183+
$vchamilo->home_path = $values['home_path'];
184+
$vchamilo->upload_path = $values['upload_path'];
185+
$vchamilo->password_encryption = $values['password_encryption'];
186+
187+
Virtual::importInstance($vchamilo, $values['version']);
188+
189+
Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
162190
}
163-
164-
$vchamilo = new stdClass();
165-
$vchamilo->main_database = $values['main_database'];
166-
$vchamilo->db_user = $values['db_user'];
167-
$vchamilo->db_password = $values['db_password'];
168-
$vchamilo->db_host = $values['db_host'];
169-
$vchamilo->root_web = $values['root_web'];
170-
$vchamilo->import_to_main_database = $values['to_main_database'];
171-
$vchamilo->import_to_db_user = $values['to_db_user'];
172-
$vchamilo->import_to_db_password = $values['to_db_password'];
173-
$vchamilo->import_to_db_host = $values['to_db_host'];
174-
$vchamilo->course_path = $values['course_path'];
175-
$vchamilo->home_path = $values['home_path'];
176-
$vchamilo->upload_path = $values['upload_path'];
177-
$vchamilo->password_encryption = $values['password_encryption'];
178-
179-
Virtual::importInstance($vchamilo, $values['version']);
180-
181-
Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
182191
}
183192
}
184193

0 commit comments

Comments
 (0)