Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60921a0

Browse files
Jami CogswellJami Cogswell
authored andcommitted
switched to checking for permission attr in application elem instead of in manifest elem
1 parent a6ecac6 commit 60921a0

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

java/ql/src/Security/CWE/CWE-926/ImplicitlyExportedAndroidComponent.ql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ import semmle.code.xml.AndroidManifest
4646
// "android.intent.category.LAUNCHER" // double-check this code (especially use of getAChild and pattern match with LAUNCHER (e.g. should I do .%LAUNCHER instead?--No, constant value per docs), etc.), and definitely need to add stuff to library for this; should use exists(...) here?
4747
// select compElem, "This component is implicitly exported."
4848
// THIRD DRAFT
49-
from AndroidComponentXmlElement compElem, AndroidManifestXmlElement manifestElem
49+
from AndroidComponentXmlElement compElem, AndroidApplicationXmlElement appElem
5050
where
5151
// Does NOT have `exported` attribute
5252
not compElem.hasAttribute("exported") and
53-
// and DOES have an intent-filter (DOUBLE-CHECK THIS CODE AND CHECK AGAINST OTHER VERSIONS THAT SEEMED TO WORK THE SAME)
54-
compElem.getAChild().hasName("intent-filter") and // compElem.getAChild("intent-filter"); need hasComponent with exists(...) here?
53+
// and DOES have an intent-filter
54+
compElem.getAChild().hasName("intent-filter") and // compElem.getAChild("intent-filter")
5555
// and does NOT have `permission` attribute
5656
not compElem.hasAttribute("permission") and
5757
// and is NOT in build directory (NOTE: switch to not isInBuildDirectory() once new predicate is merged into main)
5858
not compElem.getFile().getRelativePath().matches("%build%") and
5959
// and does NOT have a LAUNCHER category, see docs: https://developer.android.com/about/versions/12/behavior-changes-12#exported
6060
// Constant Value: "android.intent.category.LAUNCHER" from https://developer.android.com/reference/android/content/Intent#CATEGORY_LAUNCHER
61-
// I think beloew is actually filtering out too much because there can be multiple intent-filters in one component, so 2nd intent-filter without the launcher
61+
// I think below is actually filtering out too much because there can be multiple intent-filters in one component, so 2nd intent-filter without the launcher
6262
// could maybe be an issue, e.g. https://github.com/microsoft/DynamicsWOM/blob/62c2dad4cbbd4496a55aa3f644336044105bb1c1/app/src/main/AndroidManifest.xml#L56-L66
6363
not compElem.getAnIntentFilterElement().getAChild("category").getAttributeValue("name") =
64-
"android.intent.category.LAUNCHER" and // double-check this code (especially use of getAChild and pattern match with LAUNCHER (e.g. should I do .%LAUNCHER instead?--No, constant value per docs), etc.), and definitely need to add stuff to library for this; should use exists(...) here?
65-
// and NO <permission> element in manifest file since that will be applied to the component even if no `permission` attribute directly
66-
// set on component per the docs:
67-
not manifestElem.getAChild().hasName("permission")
64+
"android.intent.category.LAUNCHER" and
65+
// and NO android:permission attribute in <application> element since that will be applied to the component even
66+
// if no `permission` attribute directly set on component per the docs:
67+
not appElem.hasAttribute("permission")
6868
select compElem, "This component is implicitly exported."

java/ql/test/query-tests/security/CWE-926/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
android:roundIcon="@mipmap/ic_launcher_round"
1313
android:supportsRtl="true"
1414
android:theme="@style/Theme.HappyBirthday"
15+
android:permission="android.permission.SEND_SMS"
1516
tools:targetApi="31"> <!-- test -->
1617
<!-- Safe: category LAUNCHER --> <activity
1718
android:name=".MainActivity">

0 commit comments

Comments
 (0)