Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
610b41e8
Unverified
Commit
610b41e8
authored
Jan 26, 2022
by
Christopher Fujino
Committed by
GitHub
Jan 26, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] add validation of paths of contained files to os_utils _unpackArchive() (#96565)
parent
9cdad24d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
3 deletions
+53
-3
os.dart
packages/flutter_tools/lib/src/base/os.dart
+25
-3
os_test.dart
packages/flutter_tools/test/general.shard/base/os_test.dart
+28
-0
No files found.
packages/flutter_tools/lib/src/base/os.dart
View file @
610b41e8
...
@@ -539,10 +539,32 @@ class _WindowsUtils extends OperatingSystemUtils {
...
@@ -539,10 +539,32 @@ class _WindowsUtils extends OperatingSystemUtils {
continue
;
continue
;
}
}
final
File
destFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
final
File
destFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
canonicalize
(
_fileSystem
.
path
.
join
(
targetDirectory
.
path
,
targetDirectory
.
path
,
archiveFile
.
name
,
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
,
);
if
(!
destinationFileCanonicalPath
.
startsWith
(
targetDirectoryCanonicalPath
))
{
throw
StateError
(
'Tried to extract the file
$destinationFileCanonicalPath
outside of the '
'target directory
$targetDirectoryCanonicalPath
'
,
);
}
if
(!
destFile
.
parent
.
existsSync
())
{
if
(!
destFile
.
parent
.
existsSync
())
{
destFile
.
parent
.
createSync
(
recursive:
true
);
destFile
.
parent
.
createSync
(
recursive:
true
);
}
}
...
...
packages/flutter_tools/test/general.shard/base/os_test.dart
View file @
610b41e8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'package:archive/archive.dart'
;
import
'package:file/file.dart'
;
import
'package:file/file.dart'
;
import
'package:file/memory.dart'
;
import
'package:file/memory.dart'
;
import
'package:file_testing/file_testing.dart'
;
import
'package:file_testing/file_testing.dart'
;
...
@@ -496,6 +497,33 @@ void main() {
...
@@ -496,6 +497,33 @@ void main() {
);
);
expect
(
utils
.
name
,
'Pretty Name'
);
expect
(
utils
.
name
,
'Pretty Name'
);
});
});
// See https://snyk.io/research/zip-slip-vulnerability for more context
testWithoutContext
(
'Windows validates paths when unzipping'
,
()
{
// on POSIX systems we use the `unzip` binary, which will fail to extract
// files with paths outside the target directory
final
OperatingSystemUtils
utils
=
createOSUtils
(
FakePlatform
(
operatingSystem:
'windows'
));
final
MemoryFileSystem
fs
=
MemoryFileSystem
.
test
();
final
File
fakeZipFile
=
fs
.
file
(
'archive.zip'
);
final
Directory
targetDirectory
=
fs
.
directory
(
'output'
)..
createSync
(
recursive:
true
);
const
String
content
=
'hello, world!'
;
final
Archive
archive
=
Archive
()..
addFile
(
// This file would be extracted outside of the target extraction dir
ArchiveFile
(
r'..\..\..\Target File.txt'
,
content
.
length
,
content
.
codeUnits
),
);
final
List
<
int
>
zipData
=
ZipEncoder
().
encode
(
archive
)!;
fakeZipFile
.
writeAsBytesSync
(
zipData
);
expect
(
()
=>
utils
.
unzip
(
fakeZipFile
,
targetDirectory
),
throwsA
(
isA
<
StateError
>().
having
(
(
StateError
error
)
=>
error
.
message
,
'correct error message'
,
contains
(
'Tried to extract the file '
),
),
),
);
});
});
});
testWithoutContext
(
'If unzip fails, include stderr in exception text'
,
()
{
testWithoutContext
(
'If unzip fails, include stderr in exception text'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment