-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: Decompression Bombs #13554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
JS: Decompression Bombs #13554
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
307187f
V1
am0o0 c16a282
fix format warnings/errors
am0o0 effb802
fix yargs bug
am0o0 3bd45a8
fix query identifier
am0o0 8a80a73
fix an accident :)
am0o0 c7a7594
merge all ql files into one
am0o0 516fdf6
update stream pipe
am0o0 369bc50
fix comments
am0o0 d06444e
upgrade additional steps
am0o0 77dcd68
v2
am0o0 e81a4fc
remove CLI sources Library file and local sources for lower FPs
am0o0 faaddd4
updates for FormParsers and ReadableStream modules, add separate modu…
am0o0 eef8137
add Dice package, add global taint steps by SharedTaintStep, use getA…
am0o0 e45268c
improve and fix bugs and add Form Flow Sources test files
am0o0 f5efddc
comments improvement
am0o0 5a49f6b
fix tests
am0o0 aff6f00
comments improvement,separate module file, fix tests
am0o0 6789273
remove a test predicate
am0o0 e13050b
revert a unexpected test file
am0o0 9053ceb
revert a unexpected test file
am0o0 6f73e9c
revert for in additional steps
am0o0 4198f61
fix a qldoc isuse
am0o0 32859eb
move to experimental
am0o0 df10a7e
Merge branch 'main' into amammad-js-bombs
ghsecuritylab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
javascript/ql/src/experimental/Security/CWE-522-DecompressionBombs/DecompressionBombs.qhelp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE qhelp PUBLIC | ||
"-//Semmle//qhelp//EN" | ||
"qhelp.dtd"> | ||
<qhelp> | ||
<overview> | ||
<p>Extracting Compressed files with any compression algorithm like gzip can cause to denial of service attacks.</p> | ||
<p>Attackers can compress a huge file which created by repeated similiar byte and convert it to a small compressed file.</p> | ||
|
||
</overview> | ||
<recommendation> | ||
|
||
<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> | ||
|
||
</recommendation> | ||
<example> | ||
|
||
<p> | ||
JsZip: check uncompressedSize Object Field before extraction. | ||
</p> | ||
<sample src="jszip_good.js"/> | ||
|
||
<p> | ||
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 | ||
</p> | ||
<sample src="zlib_good.js" /> | ||
|
||
<p> | ||
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 | ||
</p> | ||
<sample src="node-tar_good.js" /> | ||
|
||
</example> | ||
<references> | ||
|
||
<li> | ||
<a href="https://github.com/advisories/GHSA-8225-6cvr-8pqp">CVE-2017-16129</a> | ||
</li> | ||
<li> | ||
<a href="https://www.bamsoftware.com/hacks/zipbomb/">A great research to gain more impact by this kind of attacks</a> | ||
</li> | ||
|
||
</references> | ||
</qhelp> |
35 changes: 35 additions & 0 deletions
35
javascript/ql/src/experimental/Security/CWE-522-DecompressionBombs/DecompressionBombs.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @name User-controlled file decompression | ||
* @description User-controlled data that flows into decompression library APIs without checking the compression rate is dangerous | ||
* @kind path-problem | ||
* @problem.severity error | ||
* @security-severity 7.8 | ||
* @precision high | ||
* @id js/user-controlled-data-decompression | ||
* @tags security | ||
* experimental | ||
* external/cwe/cwe-522 | ||
*/ | ||
|
||
import javascript | ||
import DataFlow::PathGraph | ||
import DecompressionBombs | ||
|
||
class BombConfiguration extends TaintTracking::Configuration { | ||
BombConfiguration() { this = "DecompressionBombs" } | ||
|
||
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } | ||
|
||
override predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionBomb::Sink } | ||
|
||
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) { | ||
exists(DecompressionBomb::AdditionalTaintStep addstep | | ||
addstep.isAdditionalTaintStep(pred, succ) | ||
) | ||
} | ||
} | ||
|
||
from BombConfiguration cfg, DataFlow::PathNode source, DataFlow::PathNode sink | ||
where cfg.hasFlowPath(source, sink) | ||
select sink.getNode(), source, sink, "This Decompression depends on a $@.", source.getNode(), | ||
"potentially untrusted source" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Redundant import