Skip to content

Commit b9fa856

Browse files
committed
JS: Accept alerts for DecompressionBomb
1 parent e5c4e14 commit b9fa856

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/adm-zip.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ function zipBomb(tarFile) {
2525
const zipEntries = admZip.getEntries();
2626
zipEntries.forEach(function (zipEntry) {
2727
if (zipEntry.entryName === "my_file.txt") {
28-
console.log(zipEntry.getData().toString("utf8"));
28+
console.log(zipEntry.getData().toString("utf8")); // $ Alert
2929
}
3030
});
3131
// outputs the content of file named 10GB
32-
console.log(admZip.readAsText("10GB"));
32+
console.log(admZip.readAsText("10GB")); // $ Alert
3333
// extracts the specified file to the specified location
34-
admZip.extractEntryTo("10GB", "/tmp/", false, true);
34+
admZip.extractEntryTo("10GB", "/tmp/", false, true); // $ Alert
3535
// extracts everything
36-
admZip.extractAllTo("./tmp", true);
36+
admZip.extractAllTo("./tmp", true); // $ Alert
3737
}

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/decompress.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ app.listen(3000, () => {
88
});
99

1010
app.post('/upload', async (req, res) => {
11-
decompress(req.query.filePath, 'dist').then(files => {
11+
decompress(req.query.filePath, 'dist').then(files => { // $ Alert
1212
console.log('done!');
1313
});
1414

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/jszip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function zipBombSafe(zipFile) {
3030
}
3131

3232
function zipBomb(zipFile) {
33-
jszipp.loadAsync(zipFile.data).then(function (zip) {
33+
jszipp.loadAsync(zipFile.data).then(function (zip) { // $ Alert
3434
zip.files["10GB"].async("uint8array").then(function (u8) {
3535
console.log(u8);
3636
});

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/node-tar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function zipBomb(tarFile) {
2121
const inputFile = Readable.from(tarFile.data);
2222
const outputFile = fs.createWriteStream('/tmp/untar');
2323
inputFile.pipe(
24-
tar.x()
24+
tar.x() // $ Alert
2525
).pipe(outputFile);
2626

2727
// scenario 2
@@ -30,7 +30,7 @@ function zipBomb(tarFile) {
3030
tar.x({
3131
strip: 1,
3232
C: 'some-dir'
33-
})
33+
}) // $ Alert
3434
)
3535
// safe https://github.com/isaacs/node-tar/blob/8c5af15e43a769fd24aa7f1c84d93e54824d19d2/lib/list.js#L90
3636
fs.createReadStream(tarFile.name).pipe(
@@ -47,16 +47,16 @@ function zipBomb(tarFile) {
4747
).pipe(
4848
tar.x({
4949
cwd: "dest"
50-
})
50+
}) // $ Alert
5151
)
5252

5353
// scenario 4
5454
fs.writeFileSync(tarFile.name, tarFile.data);
5555
// or using fs.writeFile
5656
// file path is a tmp file name that can get from DB after saving to DB with remote file upload
5757
// so the input file name will come from a DB source
58-
tar.x({ file: tarFile.name })
59-
tar.extract({ file: tarFile.name })
58+
tar.x({ file: tarFile.name }) // $ Alert
59+
tar.extract({ file: tarFile.name }) // $ Alert
6060
// safe https://github.com/isaacs/node-tar/blob/8c5af15e43a769fd24aa7f1c84d93e54824d19d2/lib/list.js#L90
6161
tar.x({
6262
file: tarFile.name,

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/pako.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function zipBomb1(zipFile) {
1818
const myArray = Buffer.from(new Uint8Array(zipFile.data.buffer));
1919
let output;
2020
try {
21-
output = pako.inflate(myArray);
21+
output = pako.inflate(myArray); // $ Alert
2222
console.log(output);
2323
} catch (err) {
2424
console.log(err);
@@ -29,7 +29,7 @@ function zipBomb2(zipFile) {
2929
const myArray = new Uint8Array(zipFile.data.buffer).buffer;
3030
let output;
3131
try {
32-
output = pako.inflate(myArray);
32+
output = pako.inflate(myArray); // $ Alert
3333
console.log(output);
3434
} catch (err) {
3535
console.log(err);

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/unbzip2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ app.listen(3000, () => {
99
});
1010

1111
app.post('/upload', async (req, res) => {
12-
fs.createReadStream(req.query.FilePath).pipe(bz2()).pipe(process.stdout);
12+
fs.createReadStream(req.query.FilePath).pipe(bz2()).pipe(process.stdout); // $ Alert
1313
});

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/unzipper.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ app.post('/upload', async (req, res) => {
1313
const RemoteStream = Readable.from(req.files.ZipFile.data);
1414

1515
// Unsafe
16-
RemoteStream.pipe(unzipper.Extract({ path: 'output/path' }));
16+
RemoteStream.pipe(unzipper.Extract({ path: 'output/path' })); // $ Alert
1717

1818
// Unsafe
19-
RemoteStream.pipe(unzipper.ParseOne())
19+
RemoteStream.pipe(unzipper.ParseOne()) // $ Alert
2020
.pipe(createWriteStream('firstFile.txt'));
2121

2222
// Safe because of uncompressedSize
2323
RemoteStream
24-
.pipe(unzipper.Parse())
24+
.pipe(unzipper.Parse()) // $ Alert
2525
.on('entry', function (entry) {
2626
const size = entry.vars.uncompressedSize;
2727
if (size < 1024 * 1024 * 1024) {
@@ -31,14 +31,14 @@ app.post('/upload', async (req, res) => {
3131

3232
// Unsafe
3333
RemoteStream
34-
.pipe(unzipper.Parse())
34+
.pipe(unzipper.Parse()) // $ Alert
3535
.on('entry', function (entry) {
3636
const size = entry.vars.uncompressedSize;
3737
entry.pipe(createWriteStream('output/path'));
3838
});
3939

4040
// Unsafe
41-
const zip = RemoteStream.pipe(unzipper.Parse({ forceStream: true }));
41+
const zip = RemoteStream.pipe(unzipper.Parse({ forceStream: true })); // $ Alert
4242
for await (const entry of zip) {
4343
const fileName = entry.path;
4444
if (fileName === "this IS the file I'm looking for") {
@@ -48,7 +48,7 @@ app.post('/upload', async (req, res) => {
4848
}
4949
}
5050
// Safe
51-
const zip2 = RemoteStream.pipe(unzipper.Parse({ forceStream: true }));
51+
const zip2 = RemoteStream.pipe(unzipper.Parse({ forceStream: true })); // $ Alert
5252
for await (const entry of zip2) {
5353
const size = entry.vars.uncompressedSize;
5454
if (size < 1024 * 1024 * 1024) {
@@ -57,7 +57,7 @@ app.post('/upload', async (req, res) => {
5757
}
5858

5959
// Safe because of uncompressedSize
60-
RemoteStream.pipe(unzipper.Parse())
60+
RemoteStream.pipe(unzipper.Parse()) // $ Alert
6161
.pipe(stream.Transform({
6262
objectMode: true,
6363
transform: function (entry, e, cb) {
@@ -70,7 +70,7 @@ app.post('/upload', async (req, res) => {
7070
}));
7171

7272
// Unsafe
73-
RemoteStream.pipe(unzipper.Parse())
73+
RemoteStream.pipe(unzipper.Parse()) // $ Alert
7474
.pipe(stream.Transform({
7575
objectMode: true,
7676
transform: function (entry, e, cb) {

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/yauzl.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ app.listen(3000, () => {
99
});
1010

1111
app.post('/upload', (req, res) => {
12-
yauzl.fromFd(req.files.zipFile.data)
13-
yauzl.fromBuffer(req.files.zipFile.data)
14-
yauzl.fromRandomAccessReader(req.files.zipFile.data)
12+
yauzl.fromFd(req.files.zipFile.data) // $ Alert
13+
yauzl.fromBuffer(req.files.zipFile.data) // $ Alert
14+
yauzl.fromRandomAccessReader(req.files.zipFile.data) // $ Alert
1515
// Safe
1616
yauzl.open(req.query.filePath, { lazyEntries: true }, function (err, zipfile) {
1717
if (err) throw err;
@@ -36,11 +36,11 @@ app.post('/upload', (req, res) => {
3636
// Unsafe
3737
yauzl.open(req.query.filePath, { lazyEntries: true }, function (err, zipfile) {
3838
if (err) throw err;
39-
zipfile.readEntry();
39+
zipfile.readEntry(); // $ Alert
4040
zipfile.on("entry", function (entry) {
41-
zipfile.openReadStream(entry, async function (err, readStream) {
41+
zipfile.openReadStream(entry, async function (err, readStream) { // $ Alert
4242
readStream.on("end", function () {
43-
zipfile.readEntry();
43+
zipfile.readEntry(); // $ Alert
4444
});
4545
const outputFile = fs.createWriteStream('testiness');
4646
await pipeline(

javascript/ql/test/query-tests/Security/CWE-522-DecompressionBombs/zlib.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ app.post('/upload', async (req, res) => {
2626

2727
function zlibBombAsync(zipFile) {
2828
zlib.gunzip(
29-
zipFile.data,
29+
zipFile.data, // $ Alert
3030
(err, buffer) => {
3131
});
3232
zlib.unzip(
33-
zipFile.data,
33+
zipFile.data, // $ Alert
3434
(err, buffer) => {
3535
});
3636

3737
zlib.brotliDecompress(
38-
zipFile.data,
38+
zipFile.data, // $ Alert
3939
(err, buffer) => {
4040
});
4141
}
@@ -60,9 +60,9 @@ function zlibBombAsyncSafe(zipFile) {
6060
}
6161

6262
function zlibBombSync(zipFile) {
63-
zlib.gunzipSync(zipFile.data, { finishFlush: zlib.constants.Z_SYNC_FLUSH });
64-
zlib.unzipSync(zipFile.data);
65-
zlib.brotliDecompressSync(zipFile.data);
63+
zlib.gunzipSync(zipFile.data, { finishFlush: zlib.constants.Z_SYNC_FLUSH }); // $ Alert
64+
zlib.unzipSync(zipFile.data); // $ Alert
65+
zlib.brotliDecompressSync(zipFile.data); // $ Alert
6666
}
6767

6868
function zlibBombSyncSafe(zipFile) {
@@ -74,17 +74,17 @@ function zlibBombSyncSafe(zipFile) {
7474
function zlibBombPipeStream(zipFile) {
7575
const inputStream = Readable.from(zipFile.data);
7676
const outputFile = fs.createWriteStream('unzip.txt');
77-
inputStream.pipe(zlib.createGunzip()).pipe(outputFile);
78-
inputStream.pipe(zlib.createUnzip()).pipe(outputFile);
79-
inputStream.pipe(zlib.createBrotliDecompress()).pipe(outputFile);
77+
inputStream.pipe(zlib.createGunzip()).pipe(outputFile); // $ Alert
78+
inputStream.pipe(zlib.createUnzip()).pipe(outputFile); // $ Alert
79+
inputStream.pipe(zlib.createBrotliDecompress()).pipe(outputFile); // $ Alert
8080
}
8181

8282
async function zlibBombPipeStreamPromises(zipFile) {
8383
const inputStream = Readable.from(zipFile.data);
8484
const outputFile = fs.createWriteStream('unzip.txt');
8585
await stream.pipeline(
8686
inputStream,
87-
zlib.createGunzip(),
87+
zlib.createGunzip(), // $ Alert
8888
outputFile
8989
)
9090
}

0 commit comments

Comments
 (0)