forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#12632 from egregius313/egregius313/java/and…
…roid/refactor-android-query-libraries Java: Refactor Android `Query.qll` libraries to new dataflow api
- Loading branch information
Showing
14 changed files
with
172 additions
and
96 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
java/ql/lib/change-notes/2023-03-22-deprecate-webviewdubuggingenabledquery.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: deprecated | ||
--- | ||
* The `WebViewDubuggingQuery` library has been renamed to `WebViewDebuggingQuery` to fix the typo in the file name. `WebViewDubuggingQuery` is now deprecated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
java/ql/lib/semmle/code/java/security/WebviewDebuggingEnabledQuery.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** 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%", "%test%"]) and | ||
subex.getParent*() = ex | ||
| | ||
subex.(VarAccess).getVariable().getName() = debug | ||
or | ||
subex.(MethodAccess).getMethod().hasName("getProperty") and | ||
subex.(MethodAccess).getAnArgument().(CompileTimeConstantExpr).getStringValue() = debug | ||
) | ||
} | ||
|
||
/** | ||
* DEPRECATED: Use `WebviewDebugEnabledFlow` instead. | ||
* | ||
* A configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values. | ||
*/ | ||
deprecated 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) { | ||
exists(Guard debug | isDebugCheck(debug) and debug.controls(node.asExpr().getBasicBlock(), _)) | ||
or | ||
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass | ||
} | ||
} | ||
|
||
/** A configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values. */ | ||
module WebviewDebugEnabledConfig implements DataFlow::ConfigSig { | ||
predicate isSource(DataFlow::Node node) { | ||
node.asExpr().(BooleanLiteral).getBooleanValue() = true | ||
} | ||
|
||
predicate isSink(DataFlow::Node node) { | ||
exists(MethodAccess ma | | ||
ma.getMethod().hasQualifiedName("android.webkit", "WebView", "setWebContentsDebuggingEnabled") and | ||
node.asExpr() = ma.getArgument(0) | ||
) | ||
} | ||
|
||
predicate isBarrier(DataFlow::Node node) { | ||
exists(Guard debug | isDebugCheck(debug) and debug.controls(node.asExpr().getBasicBlock(), _)) | ||
or | ||
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass | ||
} | ||
} | ||
|
||
/** | ||
* Tracks instances of `setWebContentDebuggingEnabled` with `true` values. | ||
*/ | ||
module WebviewDebugEnabledFlow = DataFlow::Global<WebviewDebugEnabledConfig>; |
46 changes: 8 additions & 38 deletions
46
java/ql/lib/semmle/code/java/security/WebviewDubuggingEnabledQuery.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,11 @@ | ||
/** Definitions for the Android Webview Debugging Enabled query */ | ||
/** | ||
* DEPRECATED: Use `semmle.code.java.security.WebviewDebuggingEnabledQuery` instead. | ||
* | ||
* 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 | ||
private import semmle.code.java.security.WebviewDebuggingEnabledQuery as WebviewDebuggingEnabledQuery | ||
|
||
/** 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%", "%test%"]) and | ||
subex.getParent*() = ex | ||
| | ||
subex.(VarAccess).getVariable().getName() = debug | ||
or | ||
subex.(MethodAccess).getMethod().hasName("getProperty") and | ||
subex.(MethodAccess).getAnArgument().(CompileTimeConstantExpr).getStringValue() = debug | ||
) | ||
} | ||
|
||
/** A 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) { | ||
exists(Guard debug | isDebugCheck(debug) and debug.controls(node.asExpr().getBasicBlock(), _)) | ||
or | ||
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass | ||
} | ||
} | ||
deprecated class WebviewDebugEnabledConfig = | ||
WebviewDebuggingEnabledQuery::WebviewDebugEnabledConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.