|
1 | 1 | /** |
2 | | - * Provides classes and predicates related to capturing summary models |
3 | | - * of the Standard or a 3rd party library. |
| 2 | + * Provides classes and predicates related to capturing summary, source, |
| 3 | + * and sink models of the Standard or a 3rd party library. |
4 | 4 | */ |
5 | 5 |
|
6 | | -import CaptureSummaryModelsSpecific |
| 6 | +private import CaptureSummaryModelsSpecific |
| 7 | +private import CaptureSinkModelsSpecific |
| 8 | +private import CaptureSourceModelsSpecific |
| 9 | +private import ModelGeneratorUtils |
7 | 10 |
|
8 | 11 | /** |
9 | 12 | * Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`). |
@@ -96,3 +99,59 @@ string captureThroughFlow(TargetApi api) { |
96 | 99 | result = asTaintModel(api, input, output) |
97 | 100 | ) |
98 | 101 | } |
| 102 | + |
| 103 | +private class FromSourceConfiguration extends TaintTracking::Configuration { |
| 104 | + FromSourceConfiguration() { this = "FromSourceConfiguration" } |
| 105 | + |
| 106 | + override predicate isSource(DataFlow::Node source) { sourceNode(source, _) } |
| 107 | + |
| 108 | + override predicate isSink(DataFlow::Node sink) { |
| 109 | + exists(TargetApi c | |
| 110 | + sink instanceof ReturnNodeExt and |
| 111 | + sink.getEnclosingCallable() = c |
| 112 | + ) |
| 113 | + } |
| 114 | + |
| 115 | + override DataFlow::FlowFeature getAFeature() { |
| 116 | + result instanceof DataFlow::FeatureHasSinkCallContext |
| 117 | + } |
| 118 | + |
| 119 | + override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 120 | + isRelevantTaintStep(node1, node2) |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +/** |
| 125 | + * Gets the source model(s) of `api`, if there is flow from an existing known source to the return of `api`. |
| 126 | + */ |
| 127 | +string captureSource(TargetApi api) { |
| 128 | + exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind | |
| 129 | + config.hasFlow(source, sink) and |
| 130 | + sourceNode(source, kind) and |
| 131 | + api = sink.getEnclosingCallable() and |
| 132 | + result = asSourceModel(api, returnNodeAsOutput(sink), kind) |
| 133 | + ) |
| 134 | +} |
| 135 | + |
| 136 | +private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific { |
| 137 | + PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" } |
| 138 | + |
| 139 | + override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) } |
| 140 | + |
| 141 | + override DataFlow::FlowFeature getAFeature() { |
| 142 | + result instanceof DataFlow::FeatureHasSourceCallContext |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +/** |
| 147 | + * Gets the sink model(s) of `api`, if there is flow from a parameter to an existing known sink. |
| 148 | + */ |
| 149 | +string captureSink(TargetApi api) { |
| 150 | + exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind | |
| 151 | + config.hasFlow(src, sink) and |
| 152 | + sinkNode(sink, kind) and |
| 153 | + api = src.getEnclosingCallable() and |
| 154 | + not kind = "logging" and |
| 155 | + result = asSinkModel(api, asInputArgument(src), kind) |
| 156 | + ) |
| 157 | +} |
0 commit comments