Skip to content

Commit 7212fb2

Browse files
committed
Work: Security: Sanitize file name that could import document with special characters - refs BT#22273
1 parent 3075eeb commit 7212fb2

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

main/inc/ajax/document.ajax.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,8 @@
153153
}
154154

155155
$resultList = [];
156-
foreach ($fileList as $file) {
157-
if (isset($_REQUEST['chunkAction']) && 'done' === $_REQUEST['chunkAction']) {
158-
// to rename and move the finished file
159-
$tmpFile = disable_dangerous_file(
160-
api_replace_dangerous_char($file['name'])
161-
);
162-
$chunkedFile = api_get_path(SYS_ARCHIVE_PATH).$tmpFile;
163-
$file['tmp_name'] = $chunkedFile;
164-
$file['size'] = filesize($chunkedFile);
165-
$file['copy_file'] = true;
166-
}
156+
foreach ($fileList as $fileInfo) {
157+
$file = processChunkedFile($fileInfo);
167158

168159
$globalFile = [];
169160
$globalFile['files'] = $file;

main/inc/ajax/dropbox.ajax.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,8 @@
7979
}
8080

8181
$resultList = [];
82-
foreach ($fileList as $file) {
83-
if (isset($_REQUEST['chunkAction']) && 'done' === $_REQUEST['chunkAction']) {
84-
// to rename and move the finished file
85-
$tmpFile = disable_dangerous_file(
86-
api_replace_dangerous_char($file['name'])
87-
);
88-
89-
// to rename and move the finished file
90-
$chunkedFile = api_get_path(SYS_ARCHIVE_PATH).$tmpFile;
91-
$file['tmp_name'] = $chunkedFile;
92-
$file['size'] = filesize($chunkedFile);
93-
$file['copy_file'] = true;
94-
}
82+
foreach ($fileList as $fileInfo) {
83+
$file = processChunkedFile($fileInfo);
9584

9685
$globalFile = [];
9786
$globalFile['files'] = $file;

main/inc/ajax/work.ajax.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,8 @@
120120
}
121121

122122
$resultList = [];
123-
foreach ($fileList as $file) {
124-
if (isset($_REQUEST['chunkAction']) && 'done' === $_REQUEST['chunkAction']) {
125-
// to rename and move the finished file
126-
$chunkedFile = api_get_path(SYS_ARCHIVE_PATH).$file['name'];
127-
$file['tmp_name'] = $chunkedFile;
128-
$file['size'] = filesize($chunkedFile);
129-
$file['copy_file'] = true;
130-
}
123+
foreach ($fileList as $fileInfo) {
124+
$file = processChunkedFile($fileInfo);
131125

132126
$globalFile = [];
133127
$globalFile['files'] = $file;

main/inc/lib/fileUpload.lib.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,3 +2255,20 @@ function getFileUploadSizeLimitForTeacher()
22552255

22562256
return $size;
22572257
}
2258+
2259+
function processChunkedFile(array $file): array
2260+
{
2261+
if (isset($_REQUEST['chunkAction']) && 'done' === $_REQUEST['chunkAction']) {
2262+
// to rename and move the finished file
2263+
$tmpFile = disable_dangerous_file(
2264+
api_replace_dangerous_char($file['name'])
2265+
);
2266+
2267+
$chunkedFile = api_get_path(SYS_ARCHIVE_PATH) . $tmpFile;
2268+
$file['tmp_name'] = $chunkedFile;
2269+
$file['size'] = filesize($chunkedFile);
2270+
$file['copy_file'] = true;
2271+
}
2272+
2273+
return $file;
2274+
}

0 commit comments

Comments
 (0)