Refactor SensitiveKeyboardCacheQuery

This commit is contained in:
Ed Minnix
2023-03-21 20:16:26 -04:00
parent d68bec98bc
commit 413a6cbc4f

View File

@@ -91,16 +91,14 @@ private predicate inputTypeFieldNotCached(Field f) {
}
/** Configuration that finds uses of `setInputType` for non cached fields. */
private class GoodInputTypeConf extends DataFlow::Configuration {
GoodInputTypeConf() { this = "GoodInputTypeConf" }
override predicate isSource(DataFlow::Node node) {
private module GoodInputTypeConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
inputTypeFieldNotCached(node.asExpr().(FieldAccess).getField())
}
override predicate isSink(DataFlow::Node node) { node.asExpr() = setInputTypeForId(_) }
predicate isSink(DataFlow::Node node) { node.asExpr() = setInputTypeForId(_) }
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(OrBitwiseExpr bitOr |
node1.asExpr() = bitOr.getAChildExpr() and
node2.asExpr() = bitOr
@@ -108,6 +106,8 @@ private class GoodInputTypeConf extends DataFlow::Configuration {
}
}
private module GoodInputTypeFlow = DataFlow::Make<GoodInputTypeConfig>;
/** Gets a regex indicating that an input field may contain sensitive data. */
private string getInputSensitiveInfoRegex() {
result =
@@ -130,8 +130,8 @@ AndroidEditableXmlElement getASensitiveCachedInput() {
result.getId().regexpMatch(getInputSensitiveInfoRegex()) and
(
not inputTypeNotCached(result.getInputType()) and
not exists(GoodInputTypeConf conf, DataFlow::Node sink |
conf.hasFlowTo(sink) and
not exists(DataFlow::Node sink |
GoodInputTypeFlow::hasFlowTo(sink) and
sink.asExpr() = setInputTypeForId(result.getId())
)
)