diff --git a/java/ql/lib/semmle/code/java/security/ImproperIntentVerificationQuery.qll b/java/ql/lib/semmle/code/java/security/ImproperIntentVerificationQuery.qll index 995f10ad3c9a..ff5ebe862178 100644 --- a/java/ql/lib/semmle/code/java/security/ImproperIntentVerificationQuery.qll +++ b/java/ql/lib/semmle/code/java/security/ImproperIntentVerificationQuery.qll @@ -51,7 +51,9 @@ private module VerifiedIntentFlow = DataFlow::Global; /** 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 } } diff --git a/java/ql/src/change-notes/2025-03-03-fix-improper-intent-verification-query.md b/java/ql/src/change-notes/2025-03-03-fix-improper-intent-verification-query.md new file mode 100644 index 000000000000..b07ffc99a969 --- /dev/null +++ b/java/ql/src/change-notes/2025-03-03-fix-improper-intent-verification-query.md @@ -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. diff --git a/java/ql/test/query-tests/security/CWE-925/AndroidManifest.xml b/java/ql/test/query-tests/security/CWE-925/AndroidManifest.xml index f9e11a1ee812..5fd3986f82c2 100644 --- a/java/ql/test/query-tests/security/CWE-925/AndroidManifest.xml +++ b/java/ql/test/query-tests/security/CWE-925/AndroidManifest.xml @@ -5,5 +5,10 @@ + + + + + - \ No newline at end of file + diff --git a/java/ql/test/query-tests/security/CWE-925/EmptyReceiverXml.java b/java/ql/test/query-tests/security/CWE-925/EmptyReceiverXml.java new file mode 100644 index 000000000000..44a81db62302 --- /dev/null +++ b/java/ql/test/query-tests/security/CWE-925/EmptyReceiverXml.java @@ -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) { } +}