Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6fdbdc

Browse files
committed
JS: deduplicate promiseTaintStep
1 parent 882b337 commit b6fdbdc

2 files changed

Lines changed: 2 additions & 39 deletions

File tree

javascript/ql/src/semmle/javascript/Promises.qll

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,6 @@
44

55
import javascript
66

7-
/**
8-
* Holds if taint propagates from `pred` to `succ` through promises.
9-
*/
10-
private predicate promiseTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
11-
// from `x` to `new Promise((res, rej) => res(x))`
12-
pred = succ.(PromiseDefinition).getResolveParameter().getACall().getArgument(0)
13-
or
14-
// from `x` to `Promise.resolve(x)`
15-
pred = succ.(ResolvedPromiseDefinition).getValue()
16-
or
17-
exists(DataFlow::MethodCallNode thn, DataFlow::FunctionNode cb |
18-
thn.getMethodName() = "then" and cb = thn.getCallback(0)
19-
|
20-
// from `p` to `x` in `p.then(x => ...)`
21-
pred = thn.getReceiver() and
22-
succ = cb.getParameter(0)
23-
or
24-
// from `v` to `p.then(x => return v)`
25-
pred = cb.getFunction().getAReturnedExpr().flow() and
26-
succ = thn
27-
)
28-
}
29-
30-
/**
31-
* An additional taint step that involves promises.
32-
*/
33-
private class PromiseTaintStep extends TaintTracking::AdditionalTaintStep {
34-
DataFlow::Node source;
35-
36-
PromiseTaintStep() { promiseTaintStep(source, this) }
37-
38-
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
39-
pred = source and succ = this
40-
}
41-
}
42-
437
/**
448
* Provides classes for working with the `bluebird` library (http://bluebirdjs.com).
459
*/

javascript/ql/src/semmle/javascript/StandardLibrary.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ private predicate promiseTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
185185
pred = succ.(PromiseDefinition).getResolveParameter().getACall().getArgument(0)
186186
or
187187
// from `x` to `Promise.resolve(x)`
188-
succ = DataFlow::globalVarRef("Promise").getAMemberCall("resolve") and
189-
pred = succ.(DataFlow::CallNode).getArgument(0)
188+
pred = succ.(ResolvedPromiseDefinition).getValue()
190189
or
191190
exists(DataFlow::MethodCallNode thn, DataFlow::FunctionNode cb |
192191
thn.getMethodName() = "then" and cb = thn.getCallback(0)
@@ -204,7 +203,7 @@ private predicate promiseTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
204203
/**
205204
* An additional taint step that involves promises.
206205
*/
207-
private class PromiseTaintStep extends TaintTracking::AdditionalTaintStep {
206+
private class PromiseTaintStep extends TaintTracking::AdditionalTaintStep {
208207
DataFlow::Node source;
209208

210209
PromiseTaintStep() { promiseTaintStep(source, this) }

0 commit comments

Comments
 (0)