Skip to content

Instantly share code, notes, and snippets.

@dllewellyn
Created November 19, 2022 21:07
Show Gist options
  • Save dllewellyn/e409f3a7b3b34cb7708b80b0e729e293 to your computer and use it in GitHub Desktop.
Save dllewellyn/e409f3a7b3b34cb7708b80b0e729e293 to your computer and use it in GitHub Desktop.
fun saveFile(fileName: String, content: String) {
val file = File("/data/is/safe/to/go/here", fileName)
val isSafe = file
.verifyFile(this) {
File("/data/is/safe/to/go/here").allowDirectory()
}
if (isSafe) { // Without this check - what would happen? Bad things..
file.writeText(content)
}
}
saveFile("../../../not/safe/to/go/here", "contents-of-malware")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment