Skip to content

Commit 13577f7

Browse files
committed
fix tests, add more comments
1 parent 21f477a commit 13577f7

17 files changed

Lines changed: 601 additions & 27 deletions

File tree

go/ql/src/experimental/CWE-522-DecompressionBombs/DecompressionBombs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import go
1515
import semmle.go.dataflow.Properties
1616
import MultipartAndFormRemoteSource
17-
import DecompressionBombs
17+
import experimental.frameworks.DecompressionBombs
1818

1919
module DecompressionBombsConfig implements DataFlow::StateConfigSig {
2020
class FlowState = DecompressionBombs::FlowState;

go/ql/src/experimental/CWE-522-DecompressionBombs/DecompressionBombs.qll renamed to go/ql/src/experimental/frameworks/DecompressionBombs.qll

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ module DecompressionBombs {
4242
abstract DataFlow::Node sink();
4343
}
4444

45+
/**
46+
* Provides Decompression Sinks and additional flow steps for `github.com/DataDog/zstd` package
47+
*/
4548
module DataDogZstd {
4649
class TheSink extends Range {
4750
TheSink() {
48-
exists(Method f |
49-
f.hasQualifiedName("github.com/klauspost/compress/zstd", "Decoder", "Read")
50-
|
51+
exists(Method f | f.hasQualifiedName("github.com/DataDog/zstd", "reader", "Read") |
5152
this = f.getACall().getReceiver()
5253
)
5354
}
@@ -78,6 +79,9 @@ module DecompressionBombs {
7879
}
7980
}
8081

82+
/**
83+
* Provides Decompression Sinks and additional flow steps for `github.com/klauspost/compress/zstd` package
84+
*/
8185
module KlauspostZstd {
8286
class TheSink extends Range {
8387
TheSink() {
@@ -121,6 +125,9 @@ module DecompressionBombs {
121125
}
122126
}
123127

128+
/**
129+
* Provides additional flow steps for `archive/zip` package
130+
*/
124131
module ArchiveZip {
125132
class TheAdditionalTaintStep extends AdditionalTaintStep {
126133
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
@@ -144,26 +151,10 @@ module DecompressionBombs {
144151
}
145152
}
146153

154+
/**
155+
* Provides Decompression additional taint steps for `github.com/klauspost/compress/zip` package
156+
*/
147157
module KlauspostZip {
148-
class TheSink extends Range {
149-
TheSink() {
150-
exists(Method f |
151-
f.hasQualifiedName("github.com/klauspost/compress/zstd", "Decoder",
152-
["WriteTo", "DecodeAll"])
153-
|
154-
this = f.getACall().getReceiver()
155-
)
156-
or
157-
exists(Method f |
158-
f.hasQualifiedName("github.com/klauspost/compress/zstd", "Decoder", "Read")
159-
|
160-
this = f.getACall().getReceiver()
161-
)
162-
}
163-
164-
override DataFlow::Node sink() { result = this }
165-
}
166-
167158
class TheAdditionalTaintStep extends AdditionalTaintStep {
168159
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
169160

@@ -200,6 +191,9 @@ module DecompressionBombs {
200191
}
201192
}
202193

194+
/**
195+
* Provides Decompression Sinks and additional taint steps for `github.com/ulikunitz/xz` package
196+
*/
203197
module UlikunitzXz {
204198
class TheSink extends Range {
205199
TheSink() {
@@ -233,6 +227,9 @@ module DecompressionBombs {
233227
}
234228
}
235229

230+
/**
231+
* Provides Decompression Sinks and additional taint steps for `compress/gzip` package
232+
*/
236233
module CompressGzip {
237234
class TheSink extends Range {
238235
TheSink() {
@@ -267,6 +264,9 @@ module DecompressionBombs {
267264
}
268265
}
269266

267+
/**
268+
* Provides Decompression Sinks and additional taint steps for `github.com/klauspost/compress/gzip` package
269+
*/
270270
module KlauspostGzip {
271271
class TheSink extends Range {
272272
TheSink() {
@@ -311,6 +311,9 @@ module DecompressionBombs {
311311
}
312312
}
313313

314+
/**
315+
* Provides Decompression Sinks and additional taint steps for `compress/bzip2` package
316+
*/
314317
module CompressBzip2 {
315318
class TheSink extends Range {
316319
TheSink() {
@@ -345,6 +348,9 @@ module DecompressionBombs {
345348
}
346349
}
347350

351+
/**
352+
* Provides Decompression Sinks and additional taint steps for `github.com/dsnet/compress/bzip2` package
353+
*/
348354
module DsnetBzip2 {
349355
class TheSink extends Range {
350356
TheSink() {
@@ -379,6 +385,9 @@ module DecompressionBombs {
379385
}
380386
}
381387

388+
/**
389+
* Provides Decompression Sinks and additional taint steps for `github.com/dsnet/compress/flate` package
390+
*/
382391
module DsnetFlate {
383392
class TheSink extends Range {
384393
TheSink() {
@@ -413,6 +422,9 @@ module DecompressionBombs {
413422
}
414423
}
415424

425+
/**
426+
* Provides Decompression Sinks and additional taint steps for `compress/flate` package
427+
*/
416428
module CompressFlate {
417429
class TheSink extends Range {
418430
TheSink() {
@@ -447,6 +459,9 @@ module DecompressionBombs {
447459
}
448460
}
449461

462+
/**
463+
* Provides Decompression Sinks and additional taint steps for `github.com/klauspost/compress/flate` package
464+
*/
450465
module KlauspostFlate {
451466
class TheSink extends Range {
452467
TheSink() {
@@ -483,6 +498,9 @@ module DecompressionBombs {
483498
}
484499
}
485500

501+
/**
502+
* Provides Decompression Sinks and additional taint steps for `github.com/klauspost/compress/zlib` package
503+
*/
486504
module KlauspostZlib {
487505
class TheSink extends Range {
488506
TheSink() {
@@ -519,6 +537,9 @@ module DecompressionBombs {
519537
}
520538
}
521539

540+
/**
541+
* Provides Decompression Sinks and additional taint steps for `compress/zlib` package
542+
*/
522543
module CompressZlib {
523544
class TheSink extends Range {
524545
TheSink() {
@@ -553,6 +574,9 @@ module DecompressionBombs {
553574
}
554575
}
555576

577+
/**
578+
* Provides Decompression Sinks and additional taint steps for `github.com/golang/snappy` package
579+
*/
556580
module GolangSnappy {
557581
class TheSink extends Range {
558582
TheSink() {
@@ -589,6 +613,9 @@ module DecompressionBombs {
589613
}
590614
}
591615

616+
/**
617+
* Provides Decompression additional taint steps for `github.com/klauspost/compress/snappy` package
618+
*/
592619
module KlauspostSnappy {
593620
class TheAdditionalTaintStep extends AdditionalTaintStep {
594621
TheAdditionalTaintStep() { this = "AdditionalTaintStep" }
@@ -613,14 +640,17 @@ module DecompressionBombs {
613640
}
614641
}
615642

643+
/**
644+
* Provides Decompression Sinks and additional taint steps for `github.com/klauspost/compress/s2` package
645+
*/
616646
module KlauspostS2 {
617647
class TheSink extends Range {
618648
TheSink() {
619-
exists(Function f |
620-
f.hasQualifiedName("github.com/klauspost/compress/s2.Reader",
649+
exists(Method m |
650+
m.hasQualifiedName("github.com/klauspost/compress/s2", "Reader",
621651
["DecodeConcurrent", "ReadByte", "Read"])
622652
|
623-
this = f.getACall().getReceiver()
653+
this = m.getACall().getReceiver()
624654
)
625655
}
626656

@@ -650,6 +680,9 @@ module DecompressionBombs {
650680
}
651681
}
652682

683+
/**
684+
* Provides Decompression Sinks for `"archive/tar` package
685+
*/
653686
module ArchiveTar {
654687
class TheSink extends Range {
655688
TheSink() {
@@ -662,6 +695,9 @@ module DecompressionBombs {
662695
}
663696
}
664697

698+
/**
699+
* Provides Decompression Sinks for packages that use some standard IO interfaces/methods for reading decompressed data
700+
*/
665701
module GeneralReadIoSink {
666702
class TheSink extends Range {
667703
TheSink() {

go/ql/test/experimental/CWE-522-DecompressionBombs/DecompressionBombs.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
WARNING: Reference to DecompressionBombs references a local library, not the named module. (/home/am/CodeQL-home/codeql-repo-amammad/go/ql/src/experimental/CWE-522-DecompressionBombs/DecompressionBombs.ql:17,8-26)
21
edges
32
| test.go:56:18:56:29 | selection of Body | test.go:165:22:165:25 | definition of file |
43
| test.go:57:15:57:26 | selection of Body | test.go:135:19:135:22 | definition of file |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Bombs
2+
3+
go 1.20
4+
5+
require (
6+
github.com/DataDog/zstd v1.5.5
7+
github.com/dsnet/compress v0.0.1
8+
github.com/golang/snappy v0.0.4
9+
github.com/klauspost/compress v1.16.6
10+
github.com/klauspost/pgzip v1.2.6
11+
github.com/ulikunitz/xz v0.5.11
12+
)

go/ql/test/experimental/CWE-522-DecompressionBombs/vendor/github.com/DataDog/zstd/stub.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/experimental/CWE-522-DecompressionBombs/vendor/github.com/dsnet/compress/flate/stub.go

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/experimental/CWE-522-DecompressionBombs/vendor/github.com/golang/snappy/stub.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/ql/test/experimental/CWE-522-DecompressionBombs/vendor/github.com/klauspost/compress/flate/stub.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)