Java: Collapse all the shared code for summary, source and sink models into a single file.

This commit is contained in:
Michael Nebel
2022-03-23 15:50:03 +01:00
parent 4f2227f206
commit 852d8a2770
6 changed files with 66 additions and 65 deletions

View File

@@ -1,9 +1,12 @@
/**
* Provides classes and predicates related to capturing summary models
* of the Standard or a 3rd party library.
* Provides classes and predicates related to capturing summary, source,
* and sink models of the Standard or a 3rd party library.
*/
import CaptureSummaryModelsSpecific
private import CaptureSummaryModelsSpecific
private import CaptureSinkModelsSpecific
private import CaptureSourceModelsSpecific
private import ModelGeneratorUtils
/**
* Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`).
@@ -96,3 +99,59 @@ string captureThroughFlow(TargetApi api) {
result = asTaintModel(api, input, output)
)
}
private class FromSourceConfiguration extends TaintTracking::Configuration {
FromSourceConfiguration() { this = "FromSourceConfiguration" }
override predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
override predicate isSink(DataFlow::Node sink) {
exists(TargetApi c |
sink instanceof ReturnNodeExt and
sink.getEnclosingCallable() = c
)
}
override DataFlow::FlowFeature getAFeature() {
result instanceof DataFlow::FeatureHasSinkCallContext
}
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
isRelevantTaintStep(node1, node2)
}
}
/**
* Gets the source model(s) of `api`, if there is flow from an existing known source to the return of `api`.
*/
string captureSource(TargetApi api) {
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
config.hasFlow(source, sink) and
sourceNode(source, kind) and
api = sink.getEnclosingCallable() and
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
)
}
private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific {
PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" }
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
override DataFlow::FlowFeature getAFeature() {
result instanceof DataFlow::FeatureHasSourceCallContext
}
}
/**
* Gets the sink model(s) of `api`, if there is flow from a parameter to an existing known sink.
*/
string captureSink(TargetApi api) {
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
config.hasFlow(src, sink) and
sinkNode(sink, kind) and
api = src.getEnclosingCallable() and
not kind = "logging" and
result = asSinkModel(api, asInputArgument(src), kind)
)
}

View File

@@ -5,7 +5,7 @@
*/
private import ModelGeneratorUtils
private import CaptureSinkModels
private import CaptureModels
from TargetApi api, string sink
where sink = captureSink(api)

View File

@@ -1,24 +0,0 @@
private import CaptureSinkModelsSpecific
private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific {
PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" }
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
override DataFlow::FlowFeature getAFeature() {
result instanceof DataFlow::FeatureHasSourceCallContext
}
}
/**
* Gets the sink model(s) of `api`, if there is flow from a parameter to an existing known sink.
*/
string captureSink(TargetApi api) {
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
config.hasFlow(src, sink) and
sinkNode(sink, kind) and
api = src.getEnclosingCallable() and
not kind = "logging" and
result = asSinkModel(api, asInputArgument(src), kind)
)
}

View File

@@ -5,7 +5,7 @@
*/
private import ModelGeneratorUtils
private import CaptureSourceModels
private import CaptureModels
from TargetApi api, string sink
where sink = captureSource(api)

View File

@@ -1,35 +0,0 @@
private import CaptureSourceModelsSpecific
private import ModelGeneratorUtils
private class FromSourceConfiguration extends TaintTracking::Configuration {
FromSourceConfiguration() { this = "FromSourceConfiguration" }
override predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
override predicate isSink(DataFlow::Node sink) {
exists(TargetApi c |
sink instanceof ReturnNodeExt and
sink.getEnclosingCallable() = c
)
}
override DataFlow::FlowFeature getAFeature() {
result instanceof DataFlow::FeatureHasSinkCallContext
}
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
isRelevantTaintStep(node1, node2)
}
}
/**
* Gets the source model(s) of `api`, if there is flow from an existing known source to the return of `api`.
*/
string captureSource(TargetApi api) {
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
config.hasFlow(source, sink) and
sourceNode(source, kind) and
api = sink.getEnclosingCallable() and
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
)
}

View File

@@ -4,7 +4,8 @@
* @id java/utils/model-generator/summary-models
*/
private import CaptureSummaryModels
private import ModelGeneratorUtils
private import CaptureModels
/**
* Capture fluent APIs that return `this`.