Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1b218a

Browse files
committed
JS: Documentation fixes
1 parent c5e57da commit c1b218a

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

javascript/ql/src/Security/CWE-022/ZipSlip.qhelp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff 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
4141
instance, 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
4849
contain 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>

javascript/ql/src/Security/CWE-022/ZipSlipBad.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
});

javascript/ql/src/Security/CWE-022/ZipSlipGood.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

javascript/ql/src/semmle/javascript/security/dataflow/ZipSlip.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)