mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-23 16:41:42 +01:00
Merge pull request #2319 from BentoBoxWorld/better_blueprint_unzip_security
Uses path normalization to prevent directory traversal attacks.
This commit is contained in:
commit
1c4be17690
@ -214,8 +214,11 @@ public class BlueprintClipboardManager {
|
||||
}
|
||||
|
||||
private void unzipFiles(final ZipInputStream zipInputStream, final Path unzipFilePath) throws IOException {
|
||||
if (!unzipFilePath.toFile().getCanonicalPath().startsWith(blueprintFolder.getCanonicalPath())) {
|
||||
throw new IOException("Entry is outside of the target directory");
|
||||
// Prevent directory traversal attacks by normalizing the path
|
||||
if (!unzipFilePath.startsWith(blueprintFolder.getCanonicalFile().toPath().normalize())) {
|
||||
throw new IOException(
|
||||
"Blueprint file is trying to write outside of the target directory! Blocked attempt to write to "
|
||||
+ unzipFilePath.toString());
|
||||
}
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(unzipFilePath.toFile().getCanonicalPath()))) {
|
||||
byte[] bytesIn = new byte[1024];
|
||||
|
Loading…
Reference in New Issue
Block a user