Merge pull request #18907 from teuron/cwe-925

[CWE-925] Intent verification is only needed on non-empty onReceive methods.
This commit is contained in:
Owen Mansel-Chan
2025-03-06 10:00:05 +00:00
committed by GitHub
4 changed files with 22 additions and 2 deletions

View File

@@ -51,7 +51,9 @@ private module VerifiedIntentFlow = DataFlow::Global<VerifiedIntentConfig>;
/** An `onReceive` method that doesn't verify the action of the intent it receives. */
private class UnverifiedOnReceiveMethod extends OnReceiveMethod {
UnverifiedOnReceiveMethod() {
not VerifiedIntentFlow::flow(DataFlow::parameterNode(this.getIntentParameter()), _)
not VerifiedIntentFlow::flow(DataFlow::parameterNode(this.getIntentParameter()), _) and
// Empty methods do not need to be verified since they do not perform any actions.
this.getBody().getNumStmt() > 0
}
}

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.

View File

@@ -5,5 +5,10 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".EmptyReceiverXml">
<intent-filter>
<action android:name"android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
</manifest>

View File

@@ -0,0 +1,9 @@
package test;
import android.content.Intent;
import android.content.Context;
import android.content.BroadcastReceiver;
class EmptyReceiverXml extends BroadcastReceiver {
@Override
public void onReceive(Context ctx, Intent intent) { }
}