Skip to content

Commit 08ee51c

Browse files
committed
JS: Move some promise-related store steps into PromiseFlow::storeStep
API graphs calls PromiseFlow::storeStep to propagate promises, which means it missed a store steps added elsewhere in the old promise library model. We want API graphs to rely on type-tracking steps in general, like in Ruby, but for now just fixing the bug.
1 parent 89410d0 commit 08ee51c

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

javascript/ql/lib/semmle/javascript/Promises.qll

+12-24
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javascript
66
private import dataflow.internal.StepSummary
7+
private import semmle.javascript.dataflow.internal.FlowSteps
78

89
/**
910
* A call to the `Promise` constructor, such as `new Promise((resolve, reject) => { ... })`.
@@ -397,6 +398,17 @@ module PromiseFlow {
397398
value = call.getCallback(0).getExceptionalReturn() and
398399
obj = call
399400
)
401+
or
402+
exists(DataFlow::FunctionNode f | f.getFunction().isAsync() |
403+
// ordinary return
404+
prop = valueProp() and
405+
value = f.getAReturn() and
406+
obj = f.getReturnNode()
407+
or
408+
// exceptional return
409+
prop = errorProp() and
410+
localExceptionStepWithAsyncFlag(value, obj, true)
411+
)
400412
}
401413

402414
/**
@@ -525,30 +537,6 @@ private class PromiseTaintStep extends TaintTracking::LegacyTaintStep {
525537
* Defines flow steps for return on async functions.
526538
*/
527539
private module AsyncReturnSteps {
528-
private predicate valueProp = Promises::valueProp/0;
529-
530-
private predicate errorProp = Promises::errorProp/0;
531-
532-
private import semmle.javascript.dataflow.internal.FlowSteps
533-
534-
/**
535-
* A data-flow step for ordinary and exceptional returns from async functions.
536-
*/
537-
private class AsyncReturn extends LegacyPreCallGraphStep {
538-
override predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
539-
exists(DataFlow::FunctionNode f | f.getFunction().isAsync() |
540-
// ordinary return
541-
prop = valueProp() and
542-
pred = f.getAReturn() and
543-
succ = f.getReturnNode()
544-
or
545-
// exceptional return
546-
prop = errorProp() and
547-
localExceptionStepWithAsyncFlag(pred, succ, true)
548-
)
549-
}
550-
}
551-
552540
/**
553541
* A data-flow step for ordinary return from an async function in a taint configuration.
554542
*/
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
| wrap-async-in-thunk.js:5:25:5:137 | /* def= ... ed() */ | Node not found on this line (but there is one on line wrap-async-in-thunk.js:14). |
2-
| wrap-async-in-thunk.js:5:25:5:137 | /* def= ... ed() */ | Node not found on this line (but there is one on line wrap-async-in-thunk.js:24). |

0 commit comments

Comments
 (0)