Skip to content

Commit 822ae55

Browse files
committed
Security: Plugin: OnlyOffice: Add filtering to new filenames created through the plugin
1 parent ab1f124 commit 822ae55

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plugin/onlyoffice/lib/onlyofficeDocumentManager.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ public static function createFile(
189189

190190
$fileTitle = Security::remove_XSS($basename).'.'.$fileExt;
191191

192-
$fileNamePrefix = ChamiloDocumentManager::getDocumentSuffix($courseInfo, $sessionId, $groupId);
193-
$fileName = preg_replace('/\.\./', '', $basename).$fileNamePrefix.'.'.$fileExt;
192+
$fileNameSuffix = ChamiloDocumentManager::getDocumentSuffix($courseInfo, $sessionId, $groupId);
193+
// Try to avoid directories browsing (remove .., slashes and backslashes)
194+
$patterns = ['#\.\./#', '#\.\.#', '#/#', '#\\\#'];
195+
$replacements = ['', '', '', ''];
196+
$fileName = preg_replace($patterns, $replacements, $basename).$fileNameSuffix.'.'.$fileExt;
194197

195198
if (empty($templatePath)) {
196199
$templatePath = TemplateManager::getEmptyTemplate($fileExt);

0 commit comments

Comments
 (0)