forked from firka/flutter
[flutter_tools] add validation of paths of contained files to os_utils _unpackArchive() (#96565)
This commit is contained in:
committed by
GitHub
parent
9cdad24df0
commit
610b41e88c
@@ -539,10 +539,32 @@ class _WindowsUtils extends OperatingSystemUtils {
|
||||
continue;
|
||||
}
|
||||
|
||||
final File destFile = _fileSystem.file(_fileSystem.path.join(
|
||||
final File destFile = _fileSystem.file(
|
||||
_fileSystem.path.canonicalize(
|
||||
_fileSystem.path.join(
|
||||
targetDirectory.path,
|
||||
archiveFile.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Validate that the destFile is within the targetDirectory we want to
|
||||
// extract to.
|
||||
//
|
||||
// See https://snyk.io/research/zip-slip-vulnerability for more context.
|
||||
final String destinationFileCanonicalPath = _fileSystem.path.canonicalize(
|
||||
destFile.path,
|
||||
);
|
||||
final String targetDirectoryCanonicalPath = _fileSystem.path.canonicalize(
|
||||
targetDirectory.path,
|
||||
archiveFile.name,
|
||||
));
|
||||
);
|
||||
if (!destinationFileCanonicalPath.startsWith(targetDirectoryCanonicalPath)) {
|
||||
throw StateError(
|
||||
'Tried to extract the file $destinationFileCanonicalPath outside of the '
|
||||
'target directory $targetDirectoryCanonicalPath',
|
||||
);
|
||||
}
|
||||
|
||||
if (!destFile.parent.existsSync()) {
|
||||
destFile.parent.createSync(recursive: true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user