77 *
88 * To track deeply tainted objects, a flow-tracking configuration should generally include the following:
99 *
10- * 1. One or more sinks associated with the label `TaintedObject::label ()`.
11- * 2. The sources from `TaintedObject::isSource `.
12- * 3. The flow steps from `TaintedObject::step `.
13- * 4. The sanitizing guards `TaintedObject::SanitizerGuard`.
10+ * 1. One or more sinks associated with the flow state `FlowState::taintedObject ()`.
11+ * 2. The sources from `TaintedObject::Source `.
12+ * 3. The flow steps from `TaintedObject::isAdditionalFlowStep `.
13+ * 4. The barriers from `TaintedObject::SanitizerGuard::getABarrierNode(state) `.
1414 */
1515
1616import javascript
@@ -22,35 +22,39 @@ module TaintedObject {
2222 import TaintedObjectCustomizations:: TaintedObject
2323
2424 // Materialize flow labels
25- private class ConcreteTaintedObjectLabel extends TaintedObjectLabel {
25+ deprecated private class ConcreteTaintedObjectLabel extends TaintedObjectLabel {
2626 ConcreteTaintedObjectLabel ( ) { this = this }
2727 }
2828
29+ deprecated predicate step ( Node src , Node trg , FlowLabel inlbl , FlowLabel outlbl ) {
30+ isAdditionalFlowStep ( src , FlowState:: fromFlowLabel ( inlbl ) , trg , FlowState:: fromFlowLabel ( outlbl ) )
31+ }
32+
2933 /**
3034 * Holds for the flows steps that are relevant for tracking user-controlled JSON objects.
3135 */
32- predicate step ( Node src , Node trg , FlowLabel inlbl , FlowLabel outlbl ) {
36+ predicate isAdditionalFlowStep ( Node src , FlowState inlbl , Node trg , FlowState outlbl ) {
3337 // JSON parsers map tainted inputs to tainted JSON
34- inlbl .isDataOrTaint ( ) and
35- outlbl = label ( ) and
38+ inlbl .isTaint ( ) and
39+ outlbl . isTaintedObject ( ) and
3640 exists ( JsonParserCall parse |
3741 src = parse .getInput ( ) and
3842 trg = parse .getOutput ( )
3943 )
4044 or
4145 // Property reads preserve deep object taint.
42- inlbl = label ( ) and
43- outlbl = label ( ) and
46+ inlbl . isTaintedObject ( ) and
47+ outlbl . isTaintedObject ( ) and
4448 trg .( PropRead ) .getBase ( ) = src
4549 or
4650 // Property projection preserves deep object taint
47- inlbl = label ( ) and
48- outlbl = label ( ) and
51+ inlbl . isTaintedObject ( ) and
52+ outlbl . isTaintedObject ( ) and
4953 trg .( PropertyProjection ) .getObject ( ) = src
5054 or
5155 // Extending objects preserves deep object taint
52- inlbl = label ( ) and
53- outlbl = label ( ) and
56+ inlbl . isTaintedObject ( ) and
57+ outlbl . isTaintedObject ( ) and
5458 exists ( ExtendCall call |
5559 src = call .getAnOperand ( ) and
5660 trg = call
@@ -60,18 +64,22 @@ module TaintedObject {
6064 )
6165 or
6266 // Spreading into an object preserves deep object taint: `p -> { ...p }`
63- inlbl = label ( ) and
64- outlbl = label ( ) and
67+ inlbl . isTaintedObject ( ) and
68+ outlbl . isTaintedObject ( ) and
6569 exists ( ObjectLiteralNode obj |
6670 src = obj .getASpreadProperty ( ) and
6771 trg = obj
6872 )
6973 }
7074
7175 /**
76+ * DEPRECATED. Use the `Source` class and `FlowState#isTaintedObject()` directly.
77+ *
7278 * Holds if `node` is a source of JSON taint and label is the JSON taint label.
7379 */
74- predicate isSource ( Node source , FlowLabel label ) { source instanceof Source and label = label ( ) }
80+ deprecated predicate isSource ( Node source , FlowLabel label ) {
81+ source instanceof Source and label = label ( )
82+ }
7583
7684 /** Request input accesses as a JSON source. */
7785 private class RequestInputAsSource extends Source {
@@ -86,11 +94,11 @@ module TaintedObject {
8694 predicate blocksExpr ( boolean outcome , Expr e ) { none ( ) }
8795
8896 /** Holds if this node blocks flow of `label` through `e`, provided it evaluates to `outcome`. */
89- predicate blocksExpr ( boolean outcome , Expr e , FlowLabel label ) { none ( ) }
97+ predicate blocksExpr ( boolean outcome , Expr e , FlowState label ) { none ( ) }
9098
9199 /** DEPRECATED. Use `blocksExpr` instead. */
92100 deprecated predicate sanitizes ( boolean outcome , Expr e , FlowLabel label ) {
93- this .blocksExpr ( outcome , e , label )
101+ this .blocksExpr ( outcome , e , FlowState :: fromFlowLabel ( label ) )
94102 }
95103
96104 /** DEPRECATED. Use `blocksExpr` instead. */
@@ -111,7 +119,7 @@ module TaintedObject {
111119 /**
112120 * A sanitizer guard that blocks deep object taint.
113121 */
114- module SanitizerGuard = DataFlow:: MakeLabeledBarrierGuard < SanitizerGuard > ;
122+ module SanitizerGuard = DataFlow:: MakeStateBarrierGuard < FlowState , SanitizerGuard > ;
115123
116124 /**
117125 * A test of form `typeof x === "something"`, preventing `x` from being an object in some cases.
@@ -133,10 +141,10 @@ module TaintedObject {
133141 )
134142 }
135143
136- override predicate blocksExpr ( boolean outcome , Expr e , FlowLabel label ) {
144+ override predicate blocksExpr ( boolean outcome , Expr e , FlowState state ) {
137145 polarity = outcome and
138146 e = operand and
139- label = label ( )
147+ state . isTaintedObject ( )
140148 }
141149 }
142150
@@ -161,8 +169,8 @@ module TaintedObject {
161169 .getACall ( )
162170 }
163171
164- override predicate blocksExpr ( boolean outcome , Expr e , FlowLabel lbl ) {
165- e = super .getAnArgument ( ) .asExpr ( ) and outcome = true and lbl = label ( )
172+ override predicate blocksExpr ( boolean outcome , Expr e , FlowState state ) {
173+ e = super .getAnArgument ( ) .asExpr ( ) and outcome = true and state . isTaintedObject ( )
166174 }
167175 }
168176
@@ -175,10 +183,10 @@ module TaintedObject {
175183
176184 JsonSchemaValidationGuard ( ) { this = call .getAValidationResultAccess ( polarity ) }
177185
178- override predicate blocksExpr ( boolean outcome , Expr e , FlowLabel label ) {
186+ override predicate blocksExpr ( boolean outcome , Expr e , FlowState state ) {
179187 outcome = polarity and
180188 e = call .getInput ( ) .asExpr ( ) and
181- label = label ( )
189+ state . isTaintedObject ( )
182190 }
183191 }
184192}
0 commit comments