Harden OS.rmdir() against symlink traversal during forced decode - #4184
Harden OS.rmdir() against symlink traversal during forced decode#4184iBotPeaches with Copilot wants to merge 2 commits into
Conversation
Previously, OS.rmdir() would treat symlinks to directories as real directories and recurse into them, potentially deleting files outside the intended path. This is a security vulnerability when using `apktool d --force` on a symlinked output directory. Fix: Use Files.isSymbolicLink() to detect symlinks before recursing. Symlinks are now deleted directly (like regular files) without following them into their targets. Closes #4183
aad85ab to
3cebe29
Compare
|
@copilot This is a very elementary change, there's no need for a whole test for that in the |
|
@copilot This is a very elementary change, there's no need for a whole test for that in the brut.j.util module that otherwise has no tests. Otherwise the change is fine as long as the user doesn't have any intentional/non-malicious use of symlinks in his project. |
Per reviewer feedback, the OS.rmdir() symlink fix is elementary enough that dedicated tests in this otherwise-test-free module are unnecessary.
Removed the test file and the
Removed the test file and the |
OS.rmdir()usedFile.isDirectory()which follows symlinks, causingapktool d --forceto recurse into symlink targets and delete files outside the intended output directory — a path traversal via symlink vulnerability.Changes
brut.j.util/OS.java: AddedFiles.isSymbolicLink()guards (NIO, does not follow symlinks) in two places withinrmdir():brut.j.util/build.gradle.kts: AddedtestImplementation(libs.junit)to enable unit tests in this modulebrut.j.util/OSTest.java: Two new unit tests covering the symlink cases — symlink as the root argument and symlink nested inside a directory being deleted