Fixed: Secure the uploads (OFBIZ-12080)

Prevents special bytes in filename
Adds some deniedFileExtensions
This commit is contained in:
Jacques Le Roux
2022-02-18 18:35:09 +01:00
parent 3f69a54891
commit 30cb6da0b1
2 changed files with 15 additions and 3 deletions
@@ -113,12 +113,13 @@ public class SecuredUpload {
return true;
}
// Prevent double extensions
// Prevents double extensions
if (StringUtils.countMatches(fileToCheck, ".") > 1) {
Debug.logError("Double extensions are not allowed for security reason", MODULE);
return false;
}
// Check max line length, default 10000
if (!checkMaxLinesLength(fileToCheck)) {
Debug.logError("For security reason lines over " + MAXLINELENGTH.toString() + " are not allowed", MODULE);
@@ -132,6 +133,17 @@ public class SecuredUpload {
// Check extensions
if (p != null && p.getFileName() != null) {
String fileName = p.getFileName().toString(); // The file name is the farthest element from the root in the directory hierarchy.
// Prevents null byte in filename
if (fileName.contains("%00")
|| fileName.contains("%0a")
|| fileName.contains("%20")
|| fileName.contains("%0d%0a")
|| fileName.contains("/")
|| fileName.contains("./")
|| fileName.contains(".")) {
Debug.logError("Special bytes in filename are not allowed for security reason", MODULE);
return false;
}
if (DENIEDFILEEXTENSIONS.contains(FilenameUtils.getExtension(fileToCheck).toLowerCase())) {
Debug.logError("This file extension is not allowed for security reason", MODULE);
deleteBadFile(fileToCheck);