|
1 | 1 | /** |
2 | | - * Provides classes for working with promises. |
| 2 | + * Provides classes for modelling promise libraries. |
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import javascript |
6 | 6 |
|
7 | | -/** |
8 | | - * A promise object created by the standard ECMAScript 2015 `Promise` constructor. |
9 | | - */ |
10 | | -private class ES2015PromiseDefinition extends PromiseDefinition, DataFlow::NewNode { |
11 | | - ES2015PromiseDefinition() { this = DataFlow::globalVarRef("Promise").getAnInstantiation() } |
12 | | - |
13 | | - override DataFlow::FunctionNode getExecutor() { result = getCallback(0) } |
14 | | -} |
15 | | - |
16 | | -/** |
17 | | - * A data flow edge from a promise reaction to the corresponding handler. |
18 | | - */ |
19 | | -private class PromiseFlowStep extends DataFlow::AdditionalFlowStep { |
20 | | - PromiseDefinition p; |
21 | | - |
22 | | - PromiseFlowStep() { this = p } |
23 | | - |
24 | | - override predicate step(DataFlow::Node pred, DataFlow::Node succ) { |
25 | | - pred = p.getResolveParameter().getACall().getArgument(0) and |
26 | | - succ = p.getAResolveHandler().getParameter(0) |
27 | | - or |
28 | | - pred = p.getRejectParameter().getACall().getArgument(0) and |
29 | | - succ = p.getARejectHandler().getParameter(0) |
30 | | - } |
31 | | -} |
32 | | - |
33 | | -/** |
34 | | - * Holds if taint propagates from `pred` to `succ` through promises. |
35 | | - */ |
36 | | -private predicate promiseTaintStep(DataFlow::Node pred, DataFlow::Node succ) { |
37 | | - // from `x` to `new Promise((res, rej) => res(x))` |
38 | | - pred = succ.(PromiseDefinition).getResolveParameter().getACall().getArgument(0) |
39 | | - or |
40 | | - // from `x` to `Promise.resolve(x)` |
41 | | - pred = succ.(ResolvedPromiseDefinition).getValue() |
42 | | - or |
43 | | - exists(DataFlow::MethodCallNode thn, DataFlow::FunctionNode cb | |
44 | | - thn.getMethodName() = "then" and cb = thn.getCallback(0) |
45 | | - | |
46 | | - // from `p` to `x` in `p.then(x => ...)` |
47 | | - pred = thn.getReceiver() and |
48 | | - succ = cb.getParameter(0) |
49 | | - or |
50 | | - // from `v` to `p.then(x => return v)` |
51 | | - pred = cb.getFunction().getAReturnedExpr().flow() and |
52 | | - succ = thn |
53 | | - ) |
54 | | -} |
55 | | - |
56 | | -/** |
57 | | - * An additional taint step that involves promises. |
58 | | - */ |
59 | | -private class PromiseTaintStep extends TaintTracking::AdditionalTaintStep { |
60 | | - DataFlow::Node source; |
61 | | - |
62 | | - PromiseTaintStep() { promiseTaintStep(source, this) } |
63 | | - |
64 | | - override predicate step(DataFlow::Node pred, DataFlow::Node succ) { |
65 | | - pred = source and succ = this |
66 | | - } |
67 | | -} |
68 | | - |
69 | 7 | /** |
70 | 8 | * Provides classes for working with the `bluebird` library (http://bluebirdjs.com). |
71 | 9 | */ |
@@ -107,24 +45,3 @@ module Q { |
107 | 45 | override DataFlow::FunctionNode getExecutor() { result = getCallback(0) } |
108 | 46 | } |
109 | 47 | } |
110 | | - |
111 | | -/** |
112 | | - * A promise that is resolved with the given value. |
113 | | - */ |
114 | | -abstract class ResolvedPromiseDefinition extends DataFlow::CallNode { |
115 | | - /** |
116 | | - * Gets the value this promise is resolved with. |
117 | | - */ |
118 | | - abstract DataFlow::Node getValue(); |
119 | | -} |
120 | | - |
121 | | -/** |
122 | | - * A resolved promise created by the standard ECMAScript 2015 `Promise.resolve` function. |
123 | | - */ |
124 | | -class ResolvedES2015PromiseDefinition extends ResolvedPromiseDefinition { |
125 | | - ResolvedES2015PromiseDefinition() { |
126 | | - this = DataFlow::globalVarRef("Promise").getAMemberCall("resolve") |
127 | | - } |
128 | | - |
129 | | - override DataFlow::Node getValue() { result = getArgument(0) } |
130 | | -} |
0 commit comments