-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Refactor Android Query.qll
libraries to new dataflow api
#12632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
egregius313
merged 12 commits into
github:main
from
egregius313:egregius313/java/android/refactor-android-query-libraries
Mar 24, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
768102e
Refactor java/android/webview-debugging-enabled
egregius313 807588a
Refactor AndroidCertificatePinningQuery
egregius313 1e0c681
Refactor UnsafeAndroidAccess
egregius313 d68bec9
Refactor CWE-940/AndroidIntentRedirection
egregius313 413a6cb
Refactor SensitiveKeyboardCacheQuery
egregius313 ef08a91
Refactor ImproperIntentVerificationQuery.qll
egregius313 e7f6d53
Deprecate `WebViewDubuggingQuery.qll`
egregius313 58bd2f7
Address code review comments
egregius313 8cc2a73
Fix test to use new InlineFlowTest
egregius313 c62eaba
Simulate deprecated import
egregius313 2eea34d
Apply suggestions from code review
egregius313 1bf4dd9
Update to DataFlow::Global
egregius313 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.