Java: Improve Android app detection#16914
Merged
Merged
Conversation
b1e6a5c to
240a2b0
Compare
240a2b0 to
b10b016
Compare
b10b016 to
e2a6358
Compare
smowton
previously approved these changes
Jul 12, 2024
smowton
left a comment
Contributor
There was a problem hiding this comment.
Suggested tidying, otherwise looks good to me
| --- | ||
| category: deprecated | ||
| --- | ||
| * The predicate `isAndroid` from the module `semmle.code.java.security.AndroidCertificatePinningQuery` has been deprecated. Use `semmle.code.java.frameworks.android.Android::inAndroidApplication(File file)` instead. |
Contributor
There was a problem hiding this comment.
Suggested change
| * The predicate `isAndroid` from the module `semmle.code.java.security.AndroidCertificatePinningQuery` has been deprecated. Use `semmle.code.java.frameworks.android.Android::inAndroidApplication(File file)` instead. | |
| * The predicate `isAndroid` from the module `semmle.code.java.security.AndroidCertificatePinningQuery` has been deprecated. Use `semmle.code.java.frameworks.android.Android::inAndroidApplication(File)` instead. |
Comment on lines
+8
to
+26
| /** | ||
| * There is an android manifest file which defines an activity, service or | ||
| * content provider (so it corresponds to an android application rather than a | ||
| * library), and `file` is in a subfolder of the folder that contains it. | ||
| */ | ||
| predicate inAndroidApplication(File file) { | ||
| file.isSourceFile() and | ||
| exists(AndroidComponentXmlElement acxe, AndroidManifestXmlFile amxf | | ||
| amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and | ||
| ( | ||
| acxe instanceof AndroidActivityXmlElement or | ||
| acxe instanceof AndroidServiceXmlElement or | ||
| acxe instanceof AndroidProviderXmlElement | ||
| ) | ||
| | | ||
| file.getParentContainer+() = amxf.getParentContainer() | ||
| ) | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| /** | |
| * There is an android manifest file which defines an activity, service or | |
| * content provider (so it corresponds to an android application rather than a | |
| * library), and `file` is in a subfolder of the folder that contains it. | |
| */ | |
| predicate inAndroidApplication(File file) { | |
| file.isSourceFile() and | |
| exists(AndroidComponentXmlElement acxe, AndroidManifestXmlFile amxf | | |
| amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and | |
| ( | |
| acxe instanceof AndroidActivityXmlElement or | |
| acxe instanceof AndroidServiceXmlElement or | |
| acxe instanceof AndroidProviderXmlElement | |
| ) | |
| | | |
| file.getParentContainer+() = amxf.getParentContainer() | |
| ) | |
| } | |
| /** | |
| * Holds if `amxf` defines at least one activity, service or contest provider, | |
| * and so it corresponds to an android application rather than a library. | |
| */ | |
| private predicate definesAndroidApplication(AndroidManifestXmlFile amxf) { | |
| exists(AndroidComponentXmlElement acxe | | |
| amxf.getManifestElement().getApplicationElement().getAComponentElement() = acxe and | |
| ( | |
| acxe instanceof AndroidActivityXmlElement or | |
| acxe instanceof AndroidServiceXmlElement or | |
| acxe instanceof AndroidProviderXmlElement | |
| ) | |
| ) | |
| } | |
| /** | |
| * Holds if in `file`'s directory or some parent directory there is an `AndroidManifestXmlFile` | |
| * that defines at least one activity, service or contest provider, suggesting this file is | |
| * part of an android application. | |
| */ | |
| predicate inAndroidApplication(File file) { | |
| file.isSourceFile() and | |
| exists(AndroidManifestXmlFile amxf, Folder amxfDir | | |
| definesAndroidApplication(amxf) and amxfDir = amxf.getParentContainer() | |
| | | |
| file.getParentContainer+() = amxfDir | |
| ) | |
| } | |
Contributor
There was a problem hiding this comment.
(rewords the comment to use Holds if, and splits it into two predicates)
Contributor
Author
|
@smowton Thanks, I've accepted those, except that I made |
smowton
previously approved these changes
Jul 15, 2024
Co-authored-by: Chris Smowton <smowton@github.com>
smowton
approved these changes
Jul 16, 2024
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change improves the detection of Android apps in the CodeQL Java standard library. It moves the detection of Android apps to one place and updates the detection to be more accurate. Previously we just required the presence of a
AndroidManifest.xmlfile anywhere in the project. This PR improves that in two ways:AndroidManifest.xmlfile must define an activity, service or content provider (so it corresponds to an android application rather than a library);AndroidManifest.xml.These are the results for "Android missing certificate pinning" which are removed by this change. I have spot-checked them and they seemed valid.