@@ -72,7 +72,10 @@ module DecompressionBombs {
72
72
* `ZipEntry.extract`
73
73
*/
74
74
class ZipSink extends DecompressionBombSink {
75
- ZipSink ( ) { this = zipInputStream ( ) .getMethod ( [ "open" , "new" ] ) .getReturn ( ) .asSource ( ) }
75
+ ZipSink ( ) {
76
+ this = zipInputStream ( ) .getMethod ( [ "open" , "new" ] ) .getReturn ( ) .asSource ( ) and
77
+ not this .getLocation ( ) .getFile ( ) .getBaseName ( ) .matches ( "%spec%" )
78
+ }
76
79
}
77
80
78
81
predicate isAdditionalTaintStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
@@ -84,25 +87,18 @@ module DecompressionBombs {
84
87
}
85
88
86
89
module ZipFile {
87
- // // Because of additional step and ZipSink predicates, I couldn't use unary predicate
88
- // // I put the explanation because I think there should be a soloution to not use other rubyZipNode predicate
89
- // API::Node rubyZipNode() {
90
- // result = zipFile() or
91
- // result = rubyZipNode().getMethod(_).getReturn() or
92
- // result = rubyZipNode().getMethod(_).getBlock().getParameter(_) or
93
- // result = rubyZipNode().getMethod(_).getParameter(0) or
94
- // result = rubyZipNode().getAnElement()
95
- // }
96
- API:: Node rubyZipNode ( API:: Node n ) {
97
- result = n
90
+ API:: Node rubyZipNode ( ) {
91
+ result = zipFile ( )
92
+ or
93
+ result = rubyZipNode ( ) .getMethod ( _)
98
94
or
99
- result = rubyZipNode ( n ) . getMethod ( _ ) .getReturn ( )
95
+ result = rubyZipNode ( ) .getReturn ( )
100
96
or
101
- result = rubyZipNode ( n ) . getMethod ( _ ) . getBlock ( ) .getParameter ( _)
97
+ result = rubyZipNode ( ) .getParameter ( _)
102
98
or
103
- result = rubyZipNode ( n ) . getMethod ( _ ) . getParameter ( 0 )
99
+ result = rubyZipNode ( ) . getAnElement ( )
104
100
or
105
- result = rubyZipNode ( n ) . getAnElement ( )
101
+ result = rubyZipNode ( ) . getBlock ( )
106
102
}
107
103
108
104
/**
@@ -113,26 +109,24 @@ module DecompressionBombs {
113
109
*/
114
110
class ZipSink extends DecompressionBombSink {
115
111
ZipSink ( ) {
116
- exists ( API:: Node zipnodes | zipnodes = zipFile ( ) |
117
- this = rubyZipNode ( zipnodes ) .getMethod ( [ "extract" , "read" ] ) .getReturn ( ) .asSource ( ) and
118
- not exists (
119
- rubyZipNode ( zipnodes ) .getMethod ( "size" ) .getReturn ( ) .getMethod ( ">" ) .getParameter ( 0 )
120
- )
112
+ exists ( API:: Node zipnodes | zipnodes = rubyZipNode ( ) |
113
+ this = zipnodes .getMethod ( [ "extract" , "read" ] ) .getReturn ( ) .asSource ( ) and
114
+ not exists ( zipnodes .getMethod ( "size" ) .getReturn ( ) .getMethod ( ">" ) .getParameter ( 0 ) )
121
115
)
122
116
}
123
117
}
124
118
125
119
predicate isAdditionalTaintStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
126
- exists ( API:: Node zipnodes | zipnodes = zipFile ( ) |
127
- nodeTo = rubyZipNode ( zipnodes ) .getMethod ( [ "extract" , "read" ] ) .getReturn ( ) .asSource ( ) and
120
+ exists ( API:: Node zipnodes | zipnodes = rubyZipNode ( ) |
121
+ nodeTo = zipnodes .getMethod ( [ "extract" , "read" ] ) .getReturn ( ) .asSource ( ) and
128
122
nodeFrom = zipnodes .getMethod ( [ "new" , "open" ] ) .getParameter ( 0 ) .asSink ( )
129
123
)
130
124
}
131
125
132
126
/**
133
127
* `Zip::File`
134
128
*/
135
- private API:: Node zipFile ( ) { result = API:: getTopLevelMember ( "Zip" ) .getMember ( "File" ) }
129
+ API:: Node zipFile ( ) { result = API:: getTopLevelCall ( "Zip" ) .getMember ( "File" ) }
136
130
}
137
131
}
138
132
@@ -148,9 +142,15 @@ class IoCopyStream extends DataFlow::CallNode {
148
142
class Bombs extends TaintTracking:: Configuration {
149
143
Bombs ( ) { this = "Decompression Bombs" }
150
144
145
+ override predicate isSanitizer ( DataFlow:: Node node ) {
146
+ not node .getLocation ( ) .hasLocationInfo ( "%spec%" , _, _, _, _)
147
+ }
148
+
151
149
override predicate isSource ( DataFlow:: Node source ) {
152
- source instanceof RemoteFlowSource or
153
- source instanceof DataFlow:: LocalSourceNode
150
+ source instanceof RemoteFlowSource
151
+ // or
152
+ // source instanceof DataFlow::LocalSourceNode
153
+ // source = API::getTopLevelCall("Zip").getMember("InputStream").getASuccessor*()
154
154
}
155
155
156
156
override predicate isSink ( DataFlow:: Node sink ) {
0 commit comments