fix(security): handle null bytes in filename + fix test assertion
CI — Build, Lint & Security Scan / backend (push) Failing after 14m30s
CI — Build, Lint & Security Scan / frontend (push) Failing after 33s
CI — Build, Lint & Security Scan / image-scan (push) Has been skipped
CI — Build, Lint & Security Scan / secrets-scan (push) Failing after 24s
Deploy to TrueNAS / deploy (push) Failing after 54s
CI — Build, Lint & Security Scan / backend (push) Failing after 14m30s
CI — Build, Lint & Security Scan / frontend (push) Failing after 33s
CI — Build, Lint & Security Scan / image-scan (push) Has been skipped
CI — Build, Lint & Security Scan / secrets-scan (push) Failing after 24s
Deploy to TrueNAS / deploy (push) Failing after 54s
- DocumentService.sanitizeFilename(): strip null bytes before FilenameUtils.getName() (commons-io rejects \0 with IllegalArgumentException) - DocumentServiceTest: fix '..' assertion — code returns 'document', not UUID
This commit is contained in:
@@ -211,9 +211,14 @@ public class DocumentService {
|
||||
if (original == null || original.isBlank()) {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
// Strip null bytes first — FilenameUtils.getName() throws on \0
|
||||
String safe = original.replace("\0", "");
|
||||
if (safe.isBlank()) {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
// Strip path components using commons-io — handles both Unix and Windows separators
|
||||
// regardless of the current platform (unlike Paths.get which is platform-dependent)
|
||||
String name = FilenameUtils.getName(original);
|
||||
String name = FilenameUtils.getName(safe);
|
||||
if (name == null || name.isBlank()) {
|
||||
return "document";
|
||||
}
|
||||
|
||||
@@ -167,10 +167,10 @@ class DocumentServiceTest {
|
||||
clubId, "Dots", DocumentCategory.SONSTIGES,
|
||||
DocumentAccessLevel.ALL_MEMBERS, null, file, uploadedBy);
|
||||
|
||||
// ".." is explicitly caught → UUID fallback
|
||||
// ".." is explicitly caught → "document" fallback
|
||||
assertThat(result.getFilename()).isNotEqualTo("..");
|
||||
assertThat(result.getFilename()).isNotBlank();
|
||||
assertThat(result.getFilename()).matches("[a-f0-9\\-]+");
|
||||
assertThat(result.getFilename()).isEqualTo("document");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user