Skip to content

Commit 8d5bbc4

Browse files
Jami CogswellJami Cogswell
authored andcommitted
first draft of query and tests
1 parent 3e09d86 commit 8d5bbc4

3 files changed

Lines changed: 51 additions & 20 deletions

File tree

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* @name Implicitly imported Android component
2+
* @name Implicitly exported Android component
33
* @description TODO after more background reading
4-
* @kind problem (TODO: confirm after more background reading)
4+
* @kind problem
55
* @problem.severity warning (TODO: confirm after more background reading)
66
* @security-severity 0.1 (TODO: run script)
7-
* @id java/android/implicitly-imported-component
7+
* @id java/android/implicitly-exported-component
88
* @tags security
99
* external/cwe/cwe-926
1010
* @precision TODO after MRVA
@@ -13,10 +13,16 @@
1313
import java
1414
import semmle.code.xml.AndroidManifest
1515

16-
// TODO: change query
17-
from AndroidXmlAttribute androidXmlAttr
16+
from AndroidComponentXmlElement compElem
1817
where
19-
androidXmlAttr.getName() = "debuggable" and
20-
androidXmlAttr.getValue() = "true" and
21-
not androidXmlAttr.getLocation().getFile().getRelativePath().matches("%build%")
22-
select androidXmlAttr, "The 'android:debuggable' attribute is enabled."
18+
not compElem.hasAttribute("exported") and
19+
compElem.getAChild().hasName("intent-filter") and
20+
not compElem.hasAttribute("permission") and
21+
not compElem
22+
.getAnIntentFilterElement()
23+
.getAnActionElement()
24+
.getActionName()
25+
.matches("android.intent.action.%") and // filter out anything that is android intent (e.g. don't just filter out MAIN) because I think those are fine (but need to look at docs to confirm)
26+
//not compElem.getAnIntentFilterElement().getAnActionElement().getActionName() = "android.intent.category.LAUNCHER" and // I should add this as well, but above will techincally filter out since they always seem to occur together
27+
not compElem.getFile().getRelativePath().matches("%build%") // switch to not isInBuildDirectory() once new predicate is merged into main
28+
select compElem, "This component is implicitly exported."
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.example.happybirthday">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:dataExtractionRules="@xml/data_extraction_rules"
9+
android:fullBackupContent="@xml/backup_rules"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/Theme.HappyBirthday"
15+
tools:targetApi="31"> <!-- test -->
16+
<!-- $ hasImplicitExport --> <activity
17+
android:name=".MainActivity">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application> <!-- test -->
25+
26+
</manifest>

java/ql/test/query-tests/security/CWE-926/ImplicitlyExportedAndroidComponentTest.ql

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import java
22
import semmle.code.xml.AndroidManifest
33
import TestUtilities.InlineExpectationsTest
44

5-
// TODO: update for implicit export query
6-
class DebuggableAttributeTrueTest extends InlineExpectationsTest {
7-
DebuggableAttributeTrueTest() { this = "DebuggableAttributeEnabledTest" }
5+
class ImplicitlyExportedAndroidComponentTest extends InlineExpectationsTest {
6+
ImplicitlyExportedAndroidComponentTest() { this = "ImplicitlyExportedAndroidComponentTest" }
87

9-
override string getARelevantTag() { result = "hasDebuggableAttributeEnabled" }
8+
override string getARelevantTag() { result = "hasImplicitExport" }
109

1110
override predicate hasActualResult(Location location, string element, string tag, string value) {
12-
tag = "hasDebuggableAttributeEnabled" and
13-
exists(AndroidXmlAttribute androidXmlAttr |
14-
androidXmlAttr.getName() = "debuggable" and
15-
androidXmlAttr.getValue() = "true" and
16-
not androidXmlAttr.getLocation().getFile().getRelativePath().matches("%build%")
11+
tag = "hasImplicitExport" and
12+
exists(AndroidComponentXmlElement compElem, AndroidIntentFilterXmlElement intFiltElem |
13+
not compElem.hasAttribute("exported") and
14+
//compElem.getAnIntentFilterElement() instanceof AndroidIntentFilterXmlElement
15+
not intFiltElem.getParent() = compElem
1716
|
18-
androidXmlAttr.getLocation() = location and
19-
element = androidXmlAttr.toString() and
17+
compElem.getLocation() = location and
18+
element = compElem.toString() and
2019
value = ""
2120
)
2221
}

0 commit comments

Comments
 (0)