mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 04:29:45 +01:00
Merge pull request #4356 from nextcloud/fix-partial-path-travel-1
Adjust cacheDir based on Android version
This commit is contained in:
commit
4ff3702f8b
@ -13,6 +13,7 @@ import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.OpenableColumns
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
@ -98,7 +99,17 @@ object FileUtils {
|
||||
fun copyFileToCache(context: Context, sourceFileUri: Uri, filename: String): File? {
|
||||
val cachedFile = File(context.cacheDir, filename)
|
||||
|
||||
if (!cachedFile.canonicalPath.startsWith(context.cacheDir.canonicalPath, true)) {
|
||||
val aboveOrEqualAPI26Check =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
!cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath())
|
||||
|
||||
val belowAPI26Check =
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
|
||||
!cachedFile.canonicalPath.startsWith(context.cacheDir.canonicalPath, true)
|
||||
|
||||
val isOutsideCacheDir = aboveOrEqualAPI26Check || belowAPI26Check
|
||||
|
||||
if (isOutsideCacheDir) {
|
||||
Log.w(TAG, "cachedFile was not created in cacheDir. Aborting for security reasons.")
|
||||
cachedFile.delete()
|
||||
return null
|
||||
|
Loading…
Reference in New Issue
Block a user