Skip to content

Commit c71586e

Browse files
Remove checks for dynamically registered recievers
1 parent 320c671 commit c71586e

File tree

7 files changed

+15
-119
lines changed

7 files changed

+15
-119
lines changed

java/ql/lib/semmle/code/java/security/ImproperIntentVerificationQuery.qll

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -55,85 +55,20 @@ string getASystemActionName() {
5555
}
5656

5757
/** An expression or XML attribute that contains the name of a system intent action. */
58-
class SystemActionName extends Top {
58+
class SystemActionName extends AndroidActionXmlElement {
5959
string name;
6060

6161
SystemActionName() {
6262
name = getASystemActionName() and
63-
(
64-
this.(CompileTimeConstantExpr).getStringValue() = "android.intent.action." + name
65-
or
66-
this.(FieldRead).getField().hasQualifiedName("android.content", "Intent", "ACTION_" + name)
67-
or
68-
this.(AndroidActionXmlElement).getActionName() = "android.intent.action." + name
69-
)
63+
this.getActionName() = "android.intent.action." + name
7064
}
7165

7266
/** Gets the name of the system intent that this expression or attribute represents. */
73-
string getName() { result = name }
74-
75-
override string toString() { result = [this.(Expr).toString(), this.(XMLAttribute).toString()] }
76-
}
77-
78-
/** A call to `Context.registerReceiver` */
79-
private class RegisterReceiverCall extends MethodAccess {
80-
RegisterReceiverCall() {
81-
this.getMethod()
82-
.getASourceOverriddenMethod*()
83-
.hasQualifiedName("android.content", "Context", "registerReceiver")
84-
}
85-
86-
/** Gets the `BroadcastReceiver` argument to this call. */
87-
Expr getReceiverArgument() { result = this.getArgument(0) }
88-
89-
/** Gets the `IntentFilter` argument to this call. */
90-
Expr getFilterArgument() { result = this.getArgument(1) }
91-
}
92-
93-
/** A configuration to detect uses of `registerReceiver` with system intent actions. */
94-
private class RegisterSystemActionConfig extends DataFlow::Configuration {
95-
RegisterSystemActionConfig() { this = "RegisterSystemActionConfig" }
96-
97-
override predicate isSource(DataFlow::Node node) { node.asExpr() instanceof SystemActionName }
98-
99-
override predicate isSink(DataFlow::Node node) {
100-
exists(RegisterReceiverCall ma | node.asExpr() = ma.getFilterArgument())
101-
}
102-
103-
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
104-
exists(ConstructorCall cc |
105-
cc.getConstructedType().hasQualifiedName("android.content", "IntentFilter") and
106-
node1.asExpr() = cc.getArgument(0) and
107-
node2.asExpr() = cc
108-
)
109-
or
110-
exists(MethodAccess ma |
111-
ma.getMethod().hasQualifiedName("android.content", "IntentFilter", "create") and
112-
node1.asExpr() = ma.getArgument(0) and
113-
node2.asExpr() = ma
114-
)
115-
or
116-
exists(MethodAccess ma |
117-
ma.getMethod().hasQualifiedName("android.content", "IntentFilter", "addAction") and
118-
node1.asExpr() = ma.getArgument(0) and
119-
node2.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr() = ma.getQualifier()
120-
)
121-
}
122-
}
123-
124-
/** Holds if `rrc` registers a receiver `orm` to receive the system action `sa` that doesn't verify the intents it receives. */
125-
private predicate registeredUnverifiedSystemReceiver(
126-
RegisterReceiverCall rrc, UnverifiedOnReceiveMethod orm, SystemActionName sa
127-
) {
128-
exists(RegisterSystemActionConfig conf, ConstructorCall cc |
129-
conf.hasFlow(DataFlow::exprNode(sa), DataFlow::exprNode(rrc.getFilterArgument())) and
130-
cc.getConstructedType() = orm.getDeclaringType() and
131-
DataFlow::localExprFlow(cc, rrc.getReceiverArgument())
132-
)
67+
string getSystemActionName() { result = name }
13368
}
13469

13570
/** Holds if the XML element `rec` declares a receiver `orm` to receive the system action named `sa` that doesn't verify intents it receives. */
136-
private predicate xmlUnverifiedSystemReceiver(
71+
predicate unverifiedSystemReceiver(
13772
AndroidReceiverXmlElement rec, UnverifiedOnReceiveMethod orm, SystemActionName sa
13873
) {
13974
exists(Class ormty |
@@ -142,9 +77,3 @@ private predicate xmlUnverifiedSystemReceiver(
14277
rec.getAnIntentFilterElement().getAnActionElement() = sa
14378
)
14479
}
145-
146-
/** Holds if `reg` registers (either explicitly or through XML) a receiver `orm` to receive the system action named `sa` that doesn't verify the intents it receives. */
147-
predicate unverifiedSystemReceiver(Top reg, Method orm, SystemActionName sa) {
148-
registeredUnverifiedSystemReceiver(reg, orm, sa) or
149-
xmlUnverifiedSystemReceiver(reg, orm, sa)
150-
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test">
2+
<application>
3+
<receiver android:name=".BootReceiverXml">
4+
<intent-filter>
5+
<action android:name="android.intent.action.BOOT_COMPLETED" />
6+
</intent-filter>
7+
</receiver>
8+
</application>
9+
</manifest>

java/ql/src/Security/CWE/CWE-925/Bad.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// ...
2-
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
3-
BroadcastReceiver sReceiver = new ShutDownReceiver();
4-
context.registerReceiver(sReceiver, filter);
5-
// ...
6-
71
public class ShutdownReceiver extends BroadcastReceiver {
82
@Override
93
public void onReceive(final Context context, final Intent intent) {

java/ql/src/Security/CWE/CWE-925/Good.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// ...
2-
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
3-
BroadcastReceiver sReceiver = new ShutDownReceiver();
4-
context.registerReceiver(sReceiver, filter);
5-
// ...
6-
71
public class ShutdownReceiver extends BroadcastReceiver {
82
@Override
93
public void onReceive(final Context context, final Intent intent) {

java/ql/src/Security/CWE/CWE-925/ImproperIntentVerification.qhelp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Otherwise, a third-party application could impersonate the system this way and c
2121
without checking that the received action is indeed <code>ACTION_SHUTDOWN</code>. This allows third-party applications to
2222
send explicit intents to this receiver to cause a denial of service.</p>
2323
<sample src="Bad.java" />
24+
<sample src="AndroidManifest.xml" />
2425
</example>
2526

2627
<recommendation>

java/ql/src/Security/CWE/CWE-925/ImproperIntentVerification.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java
1414
import semmle.code.java.security.ImproperIntentVerificationQuery
1515

16-
from Top reg, Method orm, SystemActionName sa
16+
from AndroidReceiverXmlElement reg, Method orm, SystemActionName sa
1717
where unverifiedSystemReceiver(reg, orm, sa)
1818
select orm, "This reciever doesn't verify intents it receives, and is registered $@ to receive $@.",
1919
reg, "here", sa, "the system action " + sa.getName()

java/ql/test/query-tests/security/CWE-925/ImproperIntentVerificationTest.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)