File tree Expand file tree Collapse file tree
ruby/ql/src/experimental/CWE-522-DecompressionBombs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 */
1313
1414import codeql.ruby.AST
15+ import codeql.ruby.frameworks.Files
1516import codeql.ruby.ApiGraphs
1617import codeql.ruby.DataFlow
1718import codeql.ruby.dataflow.RemoteFlowSources
@@ -135,6 +136,15 @@ module DecompressionBombs {
135136 }
136137}
137138
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+
138148class Bombs extends TaintTracking:: Configuration {
139149 Bombs ( ) { this = "Decompression Bombs" }
140150
@@ -159,11 +169,21 @@ class Bombs extends TaintTracking::Configuration {
159169 nodeTo = n .getReturn ( ) .asSource ( )
160170 )
161171 or
172+ exists ( File:: FileOpen n |
173+ nodeFrom = n .getAPathArgument ( ) and
174+ nodeTo = n
175+ )
176+ or
162177 exists ( API:: Node n | n = API:: root ( ) .getMember ( "StringIO" ) .getMethod ( "new" ) |
163178 nodeFrom = n .getParameter ( 0 ) .asSink ( ) and
164179 nodeTo = n .getReturn ( ) .asSource ( )
165180 )
166181 or
182+ exists ( IoCopyStream n |
183+ nodeFrom = n .getAPathArgument ( ) and
184+ nodeTo = n
185+ )
186+ or
167187 // following can be a global additional step
168188 exists ( DataFlow:: CallNode cn |
169189 cn .getMethodName ( ) = "open" and cn .getReceiver ( ) .toString ( ) = "self"
You can’t perform that action at this time.
0 commit comments