Skip to content

Commit fdb4375

Browse files
Jami CogswellJami Cogswell
authored andcommitted
clean up android query and tests
1 parent cf39cc0 commit fdb4375

File tree

9 files changed

+70
-21
lines changed

9 files changed

+70
-21
lines changed

java/ql/src/Security/CWE/CWE-489/DebuggableAttributeTrue.qhelp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,31 @@
44
<qhelp>
55

66
<overview>
7-
<p>The <code>debuggable</code> attribute in the application section of the AndroidManifest.xml file should
8-
never be enabled in production builds.</p>
9-
10-
<p>ADD MORE/EDIT?</p>
7+
<p>When a debugger is enabled it could allow for entry points in the application or reveal sensitive information.</p>
118

129
</overview>
1310
<recommendation>
1411

15-
<p>Make sure that the <code>debuggable</code> attribute is set to false in production builds.</p>
12+
<p>In Android applications either set the <code>android:debuggable</code> attribute to <code>false</code>
13+
or do not include it in the manifest. The default value when not included is <code>false</code>.</p>
1614

1715
</recommendation>
1816
<example>
1917

20-
<p>In the example below, the <code>debuggable</code> attribute is set to <code>true</code>.</p>
18+
<p>In the example below, the <code>android:debuggable</code> attribute is set to <code>true</code>.</p>
2119

20+
<sample src="DebuggableTrue.xml" />
2221

23-
<p>The corrected version sets the <code>debuggable</code> attribute to <code>false</code>.</p>
22+
<p>The corrected version sets the <code>android:debuggable</code> attribute to <code>false</code>.</p>
2423

24+
<sample src="DebuggableFalse.xml" />
2525

2626
</example>
2727
<references>
2828

2929
<li>
30-
Java SE Documentation:
31-
<a href="https://www.oracle.com/java/technologies/javase/codeconventions-statements.html#15395">Compound Statements</a>.
32-
</li>
33-
<li>
34-
Wikipedia:
35-
<a href="https://en.wikipedia.org/wiki/Indentation_style">Indentation style</a>.
30+
Android Developers:
31+
<a href="https://developer.android.com/guide/topics/manifest/application-element#debug">The android:debuggable attribute</a>.
3632
</li>
3733

3834
</references>

java/ql/src/Security/CWE/CWE-489/DebuggableAttributeTrue.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* @name Debuggable attribute enabled
2+
* @name Android debuggable attribute enabled
33
* @description An enabled debugger can allow for entry points in the application or reveal sensitive information.
44
* @kind problem
55
* @problem.severity warning
66
* @id java/android/debuggable-attribute-enabled
77
* @tags security
88
* external/cwe/cwe-489
99
* @precision very-high
10-
* @security-severity 0.1
10+
* @security-severity
1111
*/
1212

1313
import java
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<manifest ... >
2+
<!-- GOOD: 'android:debuggable' set to false -->
3+
<application
4+
android:debuggable="false">
5+
<activity ... >
6+
</activity>
7+
</application>
8+
</manifest>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<manifest ... >
2+
<!-- BAD: 'android:debuggable' set to true -->
3+
<application
4+
android:debuggable="true">
5+
<activity ... >
6+
</activity>
7+
</application>
8+
</manifest>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| TestTrue.xml:7:5:17:30 | debuggable=true | Warning: debuggable attribute enabled |
1+
| TestTrue.xml:7:5:17:30 | debuggable=true | The 'debuggable' attribute is enabled. |
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1-
// No need for Java code since only testing XML files
2-
public class Test { }
1+
package com.example.myapp;
2+
3+
import android.app.Fragment;
4+
import android.os.Bundle;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.Button;
9+
import androidx.fragment.app.FragmentActivity;
10+
import androidx.fragment.app.FragmentTransaction;
11+
12+
public class Test extends FragmentActivity {
13+
14+
@Override
15+
public void onCreate(Bundle savedInstance) {
16+
try {
17+
super.onCreate(savedInstance);
18+
final String fname = getIntent().getStringExtra("fname");
19+
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
20+
Class<Fragment> fClass = (Class<Fragment>) Class.forName(fname);
21+
ft.add(fClass.newInstance(), ""); // hasTaintFlow
22+
ft.add(0, Fragment.instantiate(this, fname), null); // hasTaintFlow
23+
ft.add(0, Fragment.instantiate(this, fname, null)); // hasTaintFlow
24+
ft.add(0, fClass, null, ""); // hasTaintFlow
25+
ft.add(0, fClass.newInstance(), ""); // hasTaintFlow
26+
ft.attach(fClass.newInstance()); // hasTaintFlow
27+
ft.replace(0, fClass, null); // hasTaintFlow
28+
ft.replace(0, fClass.newInstance()); // hasTaintFlow
29+
ft.replace(0, fClass, null, ""); // hasTaintFlow
30+
ft.replace(0, fClass.newInstance(), ""); // hasTaintFlow
31+
32+
ft.add(Fragment.class.newInstance(), ""); // Safe
33+
ft.attach(Fragment.class.newInstance()); // Safe
34+
ft.replace(0, Fragment.class.newInstance(), ""); // Safe
35+
} catch (Exception e) {
36+
}
37+
}
38+
39+
}

java/ql/test/query-tests/security/CWE-489/TestFalse.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.example.happybirthday">
55

6-
<!-- Safe: 'debuggable' set to false -->
6+
<!-- Safe: 'android:debuggable' set to false -->
77
<application
88
android:debuggable="false"
99
android:allowBackup="true"

java/ql/test/query-tests/security/CWE-489/TestNotSet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.example.happybirthday">
55

6-
<!-- Safe: 'debuggable' not set at all -->
6+
<!-- Safe: 'android:debuggable' not set at all -->
77
<application
88
android:allowBackup="true"
99
android:dataExtractionRules="@xml/data_extraction_rules"

java/ql/test/query-tests/security/CWE-489/TestTrue.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.example.happybirthday">
55

6-
<!-- Not Safe: 'debuggable' set to true -->
6+
<!-- Not Safe: 'android:debuggable' set to true -->
77
<application
88
android:debuggable="true"
99
android:allowBackup="true"

0 commit comments

Comments
 (0)