[flutter_tools] add validation of paths of contained files to os_utils _unpackArchive() (#96565)

This commit is contained in:
Christopher Fujino
2022-01-25 18:10:12 -08:00
committed by GitHub
parent 9cdad24df0
commit 610b41e88c
2 changed files with 53 additions and 3 deletions

View File

@@ -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);
}