mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-08-04 20:34:14 +01:00
Reject dot-only chat names to prevent zip-slip in plaintext export.
This commit is contained in:
+2
-1
@@ -435,7 +435,8 @@ object PlaintextExportRepository {
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun sanitizeFileName(name: String): String {
|
||||
return name.replace(Regex("[\\\\/:*?\"<>|]"), "_").trim().take(100)
|
||||
val sanitized = name.replace(Regex("[\\\\/:*?\"<>|]"), "_").trim().take(100)
|
||||
return if (sanitized.isEmpty() || sanitized.all { it == '.' }) "chat" else sanitized
|
||||
}
|
||||
|
||||
private fun <T> ExecutorService.submitTyped(callable: Callable<T>): Future<T> {
|
||||
|
||||
+20
@@ -723,6 +723,26 @@ class PlaintextExportRepositoryTest {
|
||||
assertEquals("My Chat Group 2024", PlaintextExportRepository.sanitizeFileName("My Chat Group 2024"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sanitizeFileName rejects dot-only names to prevent path traversal`() {
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName("."))
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName(".."))
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName("..."))
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName(" .. "))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sanitizeFileName falls back for empty result`() {
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName(""))
|
||||
assertEquals("chat", PlaintextExportRepository.sanitizeFileName(" "))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sanitizeFileName preserves names that merely contain dots`() {
|
||||
assertEquals("..hidden", PlaintextExportRepository.sanitizeFileName("..hidden"))
|
||||
assertEquals("my.chat.group", PlaintextExportRepository.sanitizeFileName("my.chat.group"))
|
||||
}
|
||||
|
||||
// ==================== getSenderName tests ====================
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user