-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDecompressionBombs.ql
More file actions
71 lines (61 loc) · 2.27 KB
/
DecompressionBombs.ql
File metadata and controls
71 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @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 rb/user-controlled-data-decompression
* @tags security
* experimental
* external/cwe/cwe-409
*/
import ruby
private import codeql.ruby.Concepts
private import codeql.ruby.DataFlow
private import codeql.ruby.TaintTracking
import DecompressionBombs
/**
* A call to `IO.copy_stream`
*/
class IoCopyStream extends DataFlow::CallNode {
IoCopyStream() { this = API::getTopLevelMember("IO").getAMethodCall("copy_stream") }
DataFlow::Node getAPathArgument() { result = this.getArgument(0) }
}
module BombsConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
predicate isSink(DataFlow::Node sink) { sink instanceof DecompressionBomb::Sink }
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
any(DecompressionBomb::AdditionalTaintStep ats).isAdditionalTaintStep(nodeFrom, nodeTo)
or
exists(API::Node n | n = API::getTopLevelMember("File").getMethod("open") |
nodeFrom = n.getParameter(0).asSink() and
nodeTo = n.getReturn().asSource()
)
or
nodeFrom = nodeTo.(File::FileOpen).getAPathArgument()
or
exists(API::Node n | n = API::getTopLevelMember("StringIO").getMethod("new") |
nodeFrom = n.getParameter(0).asSink() and
nodeTo = n.getReturn().asSource()
)
or
nodeFrom = nodeTo.(IoCopyStream).getAPathArgument()
or
// following can be a global additional step
exists(DataFlow::CallNode cn |
cn.getMethodName() = "open" and
cn.getReceiver().getExprNode().getExpr() instanceof Ast::SelfVariableAccess
|
nodeFrom = cn.getArgument(0) and
nodeTo = cn
)
}
predicate observeDiffInformedIncrementalMode() { any() }
}
module Bombs = TaintTracking::Global<BombsConfig>;
import Bombs::PathGraph
from Bombs::PathNode source, Bombs::PathNode sink
where Bombs::flowPath(source, sink)
select sink.getNode(), source, sink, "This file Decompression depends on a $@.", source.getNode(),
"potentially untrusted source"