Merge pull request #3064 from TR-SLimey/fix-path-traversal-file-save-api29
When downloading a file in <= API 29, replace dangerous characters with underscores
This commit is contained in:
commit
5c89179c47
@ -514,7 +514,7 @@ fun selectTxtFileToWrite(
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: String?): File? {
|
fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: String?): File? {
|
||||||
// defines another name for the external media
|
// defines another name for the external media
|
||||||
val dstFileName: String
|
var dstFileName: String
|
||||||
|
|
||||||
// build a filename is not provided
|
// build a filename is not provided
|
||||||
if (null == outputFilename) {
|
if (null == outputFilename) {
|
||||||
@ -529,6 +529,9 @@ fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: Strin
|
|||||||
dstFileName = outputFilename
|
dstFileName = outputFilename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove dangerous characters from the filename
|
||||||
|
dstFileName = dstFileName.replace(Regex("""[/\\]"""), "_")
|
||||||
|
|
||||||
var dstFile = File(dstDirPath, dstFileName)
|
var dstFile = File(dstDirPath, dstFileName)
|
||||||
|
|
||||||
// if the file already exists, append a marker
|
// if the file already exists, append a marker
|
||||||
|
Loading…
Reference in New Issue
Block a user