File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
ruby/ql/src/experimental/CWE-522-DecompressionBombs Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 12
12
*/
13
13
14
14
import codeql.ruby.AST
15
+ import codeql.ruby.frameworks.Files
15
16
import codeql.ruby.ApiGraphs
16
17
import codeql.ruby.DataFlow
17
18
import codeql.ruby.dataflow.RemoteFlowSources
@@ -135,6 +136,15 @@ module DecompressionBombs {
135
136
}
136
137
}
137
138
139
+ /**
140
+ * A call to `IO.copy_stream`
141
+ */
142
+ class IoCopyStream extends DataFlow:: CallNode {
143
+ IoCopyStream ( ) { this = API:: getTopLevelMember ( "IO" ) .getAMethodCall ( "copy_stream" ) }
144
+
145
+ DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( 0 ) }
146
+ }
147
+
138
148
class Bombs extends TaintTracking:: Configuration {
139
149
Bombs ( ) { this = "Decompression Bombs" }
140
150
@@ -159,11 +169,21 @@ class Bombs extends TaintTracking::Configuration {
159
169
nodeTo = n .getReturn ( ) .asSource ( )
160
170
)
161
171
or
172
+ exists ( File:: FileOpen n |
173
+ nodeFrom = n .getAPathArgument ( ) and
174
+ nodeTo = n
175
+ )
176
+ or
162
177
exists ( API:: Node n | n = API:: root ( ) .getMember ( "StringIO" ) .getMethod ( "new" ) |
163
178
nodeFrom = n .getParameter ( 0 ) .asSink ( ) and
164
179
nodeTo = n .getReturn ( ) .asSource ( )
165
180
)
166
181
or
182
+ exists ( IoCopyStream n |
183
+ nodeFrom = n .getAPathArgument ( ) and
184
+ nodeTo = n
185
+ )
186
+ or
167
187
// following can be a global additional step
168
188
exists ( DataFlow:: CallNode cn |
169
189
cn .getMethodName ( ) = "open" and cn .getReceiver ( ) .toString ( ) = "self"
You can’t perform that action at this time.
0 commit comments