File tree Expand file tree Collapse file tree
semmle/javascript/security/dataflow Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,19 +36,32 @@ to prevent writing files to unexpected locations.</p>
3636
3737<example >
3838<p >
39- Here is an example of extracting an archive without validating
40- filenames. If <code >archive.zip</code > contained relative paths (for
39+ In this example an archive is extracted without validating file paths.
40+ If <code >archive.zip</code > contained relative paths (for
4141instance, if it were created by something like <code >zip archive.zip
42- ../file.txt</code >) then executing this code would write to those paths.
42+ ../file.txt</code >) then executing this code could write to locations
43+ outside the destination directory.
4344</p >
4445
4546<sample src =" ZipSlipBad.js" />
4647
47- <p >To fix this vulnerability, we can to check that the path does not
48+ <p >To fix this vulnerability, we need to check that the path does not
4849contain any <code >".."</code > elements in it.
4950</p >
5051
5152<sample src =" ZipSlipGood.js" />
5253
5354</example >
55+ <references >
56+
57+ <li >
58+ Snyk:
59+ <a href =" https://snyk.io/research/zip-slip-vulnerability" >Zip Slip Vulnerability</a >.
60+ </li >
61+ <li >
62+ OWASP:
63+ <a href =" https://www.owasp.org/index.php/Path_traversal" >Path Traversal</a >.
64+ </li >
65+
66+ </references >
5467</qhelp >
Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ fs.createReadStream('archive.zip')
55 . pipe ( unzip . Parse ( ) )
66 . on ( 'entry' , entry => {
77 const fileName = entry . path ;
8+ // BAD: This could write any file on the filesystem.
89 entry . pipe ( fs . createWriteStream ( fileName ) ) ;
910 } ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ fs.createReadStream('archive.zip')
55 . pipe ( unzip . Parse ( ) )
66 . on ( 'entry' , entry => {
77 const fileName = entry . path ;
8+ // GOOD: ensures the path is safe to write to.
89 if ( fileName . indexOf ( '..' ) == - 1 ) {
910 entry . pipe ( fs . createWriteStream ( fileName ) ) ;
1011 }
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ module ZipSlip {
7878 CreateWriteStreamSink ( ) {
7979 // This is not covered by `FileSystemWriteSink`, because it is
8080 // required that a write actually takes place to the stream.
81- // However, we want to consider even the bare createWriteStream
81+ // However, we want to consider even the bare ` createWriteStream`
8282 // to be a zipslip vulnerability since it may truncate an
8383 // existing file.
8484 this = DataFlow:: moduleImport ( "fs" ) .getAMemberCall ( "createWriteStream" ) .getArgument ( 0 )
@@ -91,8 +91,8 @@ module ZipSlip {
9191 }
9292
9393 /**
94- * Gets a string which suffices to search for to ensure that a
95- * filepath will not refer to parent directories.
94+ * Gets a string which is sufficient to exclude to make
95+ * a filepath definitely not refer to parent directories.
9696 */
9797 private string getAParentDirName ( ) { result = ".." or result = "../" }
9898
You can’t perform that action at this time.
0 commit comments