Skip to content

Commit 24983a5

Browse files
committed
JS: Add OptionalStep and OptionalBarrier MaD tokens
OptionalStep[foo] and OptionalBarrier[foo] contribute steps/barriers that are not active by default, but can be opted into by specific queries or for specific flow states. (Will be used in the following commits)
1 parent 87454a4 commit 24983a5

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/Contents.qll

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,20 @@ module Private {
9393
// than an ordinary content component. These special content sets should never appear in a step.
9494
MkAwaited() or
9595
MkAnyPropertyDeep() or
96-
MkArrayElementDeep()
96+
MkArrayElementDeep() or
97+
MkOptionalStep(string name) { isAccessPathTokenPresent("OptionalStep", name) } or
98+
MkOptionalBarrier(string name) { isAccessPathTokenPresent("OptionalBarrier", name) }
9799

98100
/**
99101
* Holds if `cs` is used to encode a special operation as a content component, but should not
100102
* be treated as an ordinary content component.
101103
*/
102104
predicate isSpecialContentSet(ContentSet cs) {
103-
cs = MkAwaited() or cs = MkAnyPropertyDeep() or cs = MkArrayElementDeep()
105+
cs = MkAwaited() or
106+
cs = MkAnyPropertyDeep() or
107+
cs = MkArrayElementDeep() or
108+
cs instanceof MkOptionalStep or
109+
cs instanceof MkOptionalBarrier
104110
}
105111
}
106112

@@ -288,6 +294,16 @@ module Public {
288294
or
289295
this = MkAnyCapturedContent() and
290296
result = "AnyCapturedContent"
297+
or
298+
exists(string name |
299+
this = MkOptionalStep(name) and
300+
result = "OptionalStep[" + name + "]"
301+
)
302+
or
303+
exists(string name |
304+
this = MkOptionalBarrier(name) and
305+
result = "OptionalBarrier[" + name + "]"
306+
)
291307
}
292308
}
293309

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
10351035
FlowSummaryPrivate::Steps::summaryReadStep(input, MkAwaited(), output) and
10361036
node1 = TFlowSummaryNode(input) and
10371037
node2 = TFlowSummaryNode(output)
1038+
or
1039+
// Add flow through optional barriers. This step is then blocked by the barrier for queries that choose to use the barrier.
1040+
FlowSummaryPrivate::Steps::summaryReadStep(input, MkOptionalBarrier(_), output) and
1041+
node1 = TFlowSummaryNode(input) and
1042+
node2 = TFlowSummaryNode(output)
10381043
)
10391044
or
10401045
VariableCaptureOutput::localFlowStep(getClosureNode(node1), getClosureNode(node2))
@@ -1389,3 +1394,20 @@ class ArgumentNode extends DataFlow::Node {
13891394
class ParameterNode extends DataFlow::Node {
13901395
ParameterNode() { isParameterNodeImpl(this, _, _) }
13911396
}
1397+
1398+
cached
1399+
private module OptionalSteps {
1400+
cached
1401+
predicate optionalStep(Node node1, string name, Node node2) {
1402+
FlowSummaryPrivate::Steps::summaryReadStep(node1.(FlowSummaryNode).getSummaryNode(),
1403+
MkOptionalStep(name), node2.(FlowSummaryNode).getSummaryNode())
1404+
}
1405+
1406+
cached
1407+
predicate optionalBarrier(Node node, string name) {
1408+
FlowSummaryPrivate::Steps::summaryReadStep(_, MkOptionalBarrier(name),
1409+
node.(FlowSummaryNode).getSummaryNode())
1410+
}
1411+
}
1412+
1413+
import OptionalSteps

javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSummaryPrivate.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ private string encodeContentAux(ContentSet cs, string arg) {
9595
cs = MkAnyPropertyDeep() and result = "AnyMemberDeep" and arg = ""
9696
or
9797
cs = MkArrayElementDeep() and result = "ArrayElementDeep" and arg = ""
98+
or
99+
cs = MkOptionalStep(arg) and result = "OptionalStep"
100+
or
101+
cs = MkOptionalBarrier(arg) and result = "OptionalBarrier"
98102
}
99103

100104
/**

0 commit comments

Comments
 (0)