Add webview debugging query

This commit is contained in:
Joe Farebrother
2022-08-26 16:34:06 +01:00
parent 82c3e53694
commit 20b2956322
2 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/** Definitions for the Android Webview Debugging Enabled query */
import java
import semmle.code.java.dataflow.DataFlow
import semmle.code.java.controlflow.Guards
import semmle.code.java.security.SecurityTests
/** Holds if `ex` looks like a check that this is a debug build. */
private predicate isDebugCheck(Expr ex) {
exists(Expr subex, string debug |
debug.toLowerCase().matches("%debug%") and
subex.getParent*() = ex
|
subex.(VarAccess).getVariable().getName() = debug
or
subex.(MethodAccess).getMethod().hasName("getProperty") and
subex.(MethodAccess).getAnArgument().(CompileTimeConstantExpr).getStringValue() = debug
)
}
/** Configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values. */
class WebviewDebugEnabledConfig extends DataFlow::Configuration {
WebviewDebugEnabledConfig() { this = "WebviewDebugEnabledConfig" }
override predicate isSource(DataFlow::Node node) {
node.asExpr().(BooleanLiteral).getBooleanValue() = true
}
override predicate isSink(DataFlow::Node node) {
exists(MethodAccess ma |
ma.getMethod().hasQualifiedName("android.webkit", "WebView", "setWebContentsDebuggingEnabled") and
node.asExpr() = ma.getArgument(0)
)
}
override predicate isBarrier(DataFlow::Node node) {
not node.getType() instanceof BooleanType
or
exists(Guard debug | isDebugCheck(debug) and debug.controls(node.asExpr().getBasicBlock(), _))
or
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass
}
}