Skip to content

Commit 499c4df

Browse files
authored
Merge pull request #13554 from am0o0/amammad-js-bombs
JS: Decompression Bombs
2 parents a2994c0 + df10a7e commit 499c4df

28 files changed

+2200
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>Extracting Compressed files with any compression algorithm like gzip can cause to denial of service attacks.</p>
7+
<p>Attackers can compress a huge file which created by repeated similiar byte and convert it to a small compressed file.</p>
8+
9+
</overview>
10+
<recommendation>
11+
12+
<p>When you want to decompress a user-provided compressed file you must be careful about the decompression ratio or read these files within a loop byte by byte to be able to manage the decompressed size in each cycle of the loop.</p>
13+
14+
</recommendation>
15+
<example>
16+
17+
<p>
18+
JsZip: check uncompressedSize Object Field before extraction.
19+
</p>
20+
<sample src="jszip_good.js"/>
21+
22+
<p>
23+
nodejs Zlib: use <a href="https://nodejs.org/dist/latest-v18.x/docs/api/zlib.html#class-options">maxOutputLength option</a> which it'll limit the buffer read size
24+
</p>
25+
<sample src="zlib_good.js" />
26+
27+
<p>
28+
node-tar: use <a href="https://github.com/isaacs/node-tar/blob/8c5af15e43a769fd24aa7f1c84d93e54824d19d2/lib/list.js#L90">maxReadSize option</a> which it'll limit the buffer read size
29+
</p>
30+
<sample src="node-tar_good.js" />
31+
32+
</example>
33+
<references>
34+
35+
<li>
36+
<a href="https://github.com/advisories/GHSA-8225-6cvr-8pqp">CVE-2017-16129</a>
37+
</li>
38+
<li>
39+
<a href="https://www.bamsoftware.com/hacks/zipbomb/">A great research to gain more impact by this kind of attacks</a>
40+
</li>
41+
42+
</references>
43+
</qhelp>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @name User-controlled file decompression
3+
* @description User-controlled data that flows into decompression library APIs without checking the compression rate is dangerous
4+
* @kind path-problem
5+
* @problem.severity error
6+
* @security-severity 7.8
7+
* @precision high
8+
* @id js/user-controlled-data-decompression
9+
* @tags security
10+
* experimental
11+
* external/cwe/cwe-522
12+
*/
13+
14+
import javascript
15+
import DataFlow::PathGraph
16+
import DecompressionBombs
17+
18+
class BombConfiguration extends TaintTracking::Configuration {
19+
BombConfiguration() { this = "DecompressionBombs" }
20+
21+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
22+
23+
override predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionBomb::Sink }
24+
25+
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
26+
exists(DecompressionBomb::AdditionalTaintStep addstep |
27+
addstep.isAdditionalTaintStep(pred, succ)
28+
)
29+
}
30+
}
31+
32+
from BombConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
33+
where cfg.hasFlowPath(source, sink)
34+
select sink.getNode(), source, sink, "This Decompression depends on a $@.", source.getNode(),
35+
"potentially untrusted source"

0 commit comments

Comments
 (0)