Skip to content

Commit cbe7edd

Browse files
authored
Merge pull request #18907 from teuron/cwe-925
[CWE-925] Intent verification is only needed on non-empty onReceive methods.
2 parents 2692b8f + 32e1589 commit cbe7edd

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ private module VerifiedIntentFlow = DataFlow::Global<VerifiedIntentConfig>;
5151
/** An `onReceive` method that doesn't verify the action of the intent it receives. */
5252
private class UnverifiedOnReceiveMethod extends OnReceiveMethod {
5353
UnverifiedOnReceiveMethod() {
54-
not VerifiedIntentFlow::flow(DataFlow::parameterNode(this.getIntentParameter()), _)
54+
not VerifiedIntentFlow::flow(DataFlow::parameterNode(this.getIntentParameter()), _) and
55+
// Empty methods do not need to be verified since they do not perform any actions.
56+
this.getBody().getNumStmt() > 0
5557
}
5658
}
5759

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Overrides of `BroadcastReceiver::onReceive` with no statements in their body are no longer considered unverified by the `java/improper-intent-verification` query. This will reduce false positives from `onReceive` methods which do not perform any actions.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
<action android:name="android.intent.action.BOOT_COMPLETED" />
66
</intent-filter>
77
</receiver>
8+
<receiver android:name=".EmptyReceiverXml">
9+
<intent-filter>
10+
<action android:name"android.intent.action.BOOT_COMPLETED" />
11+
</intent-filter>
12+
</receiver>
813
</application>
9-
</manifest>
14+
</manifest>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test;
2+
import android.content.Intent;
3+
import android.content.Context;
4+
import android.content.BroadcastReceiver;
5+
6+
class EmptyReceiverXml extends BroadcastReceiver {
7+
@Override
8+
public void onReceive(Context ctx, Intent intent) { }
9+
}

0 commit comments

Comments
 (0)