-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Java: Improve Android app detection #16914
Conversation
b1e6a5c
to
240a2b0
Compare
240a2b0
to
b10b016
Compare
b10b016
to
e2a6358
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. |
/** | ||
* 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() | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* 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 | |
) | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(rewords the comment to use Holds if
, and splits it into two predicates)
@smowton Thanks, I've accepted those, except that I made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (one typo)
Co-authored-by: Chris Smowton <[email protected]>
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.xml
file anywhere in the project. This PR improves that in two ways:AndroidManifest.xml
file 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.