mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Apply suggestions from code review - fix typos/style, make things private
Co-authored-by: Tony Torralba <atorralba@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ private class OnReceiveMethod extends Method {
|
||||
.hasQualifiedName("android.content", "BroadcastReceiver", "onReceive")
|
||||
}
|
||||
|
||||
/** Gets the paramter of this method that holds the received `Intent`. */
|
||||
/** Gets the parameter of this method that holds the received `Intent`. */
|
||||
Parameter getIntentParameter() { result = this.getParameter(1) }
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ private class VerifiedIntentConfig extends DataFlow::Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
/** An `onReceive` method that doesn't verify the action of the intent it recieves. */
|
||||
/** An `onReceive` method that doesn't verify the action of the intent it receives. */
|
||||
class UnverifiedOnReceiveMethod extends OnReceiveMethod {
|
||||
UnverifiedOnReceiveMethod() {
|
||||
not any(VerifiedIntentConfig c).hasFlow(DataFlow::parameterNode(this.getIntentParameter()), _)
|
||||
@@ -70,7 +70,7 @@ class SystemActionName extends Top {
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the name of the system intent that this expression or attriute represents. */
|
||||
/** Gets the name of the system intent that this expression or attribute represents. */
|
||||
string getName() { result = name }
|
||||
|
||||
override string toString() {
|
||||
@@ -125,8 +125,8 @@ private class RegisterSystemActionConfig extends DataFlow::Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
/** Holds if `rrc` registers a reciever `orm` to recieve the system action `sa` that doesn't verifiy intents it recieves. */
|
||||
predicate registeredUnverifiedSystemReceiver(
|
||||
/** Holds if `rrc` registers a receiver `orm` to receive the system action `sa` that doesn't verify the intents it receives. */
|
||||
private predicate registeredUnverifiedSystemReceiver(
|
||||
RegisterReceiverCall rrc, UnverifiedOnReceiveMethod orm, SystemActionName sa
|
||||
) {
|
||||
exists(RegisterSystemActionConfig conf, ConstructorCall cc |
|
||||
@@ -136,8 +136,8 @@ predicate registeredUnverifiedSystemReceiver(
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if the XML element `rec` declares a reciever `orm` to recieve the system action named `sa` that doesn't verifiy intents it recieves. */
|
||||
predicate xmlUnverifiedSystemReceiver(
|
||||
/** Holds if the XML element `rec` declares a receiver `orm` to receive the system action named `sa` that doesn't verify intents it receives. */
|
||||
private predicate xmlUnverifiedSystemReceiver(
|
||||
XMLElement rec, UnverifiedOnReceiveMethod orm, SystemActionName sa
|
||||
) {
|
||||
exists(XMLElement filter, XMLElement action, Class ormty |
|
||||
@@ -152,7 +152,7 @@ predicate xmlUnverifiedSystemReceiver(
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if `reg` registers (either explicitly or through XML) a reciever `orm` to recieve the system action named `sa` that doesn't verify intents it recieves. */
|
||||
/** 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. */
|
||||
predicate unverifiedSystemReceiver(Top reg, Method orm, SystemActionName sa) {
|
||||
registeredUnverifiedSystemReceiver(reg, orm, sa) or
|
||||
xmlUnverifiedSystemReceiver(reg, orm, sa)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
...
|
||||
// ...
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
|
||||
BroadcastReceiver sReceiver = new ShutDownReceiver();
|
||||
context.registerReceiver(sReceiver, filter);
|
||||
...
|
||||
// ...
|
||||
|
||||
public class ShutdownReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
...
|
||||
// ...
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
|
||||
BroadcastReceiver sReceiver = new ShutDownReceiver();
|
||||
context.registerReceiver(sReceiver, filter);
|
||||
...
|
||||
// ...
|
||||
|
||||
public class ShutdownReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
When an android application uses a <code>BroadcastReciever</code> to receive Intents,
|
||||
it is also able to receive explicit Intents that are sent drctly to it, egardless of its filter.
|
||||
When an android application uses a <code>BroadcastReciever</code> to receive intents,
|
||||
it is also able to receive explicit intents that are sent directly to it, regardless of its filter.
|
||||
|
||||
Certain intent actions are only able to be sent by the operating system, not third-party applications.
|
||||
However, a <code>BroadcastReceiver</code> that is registered to recieve system intents is still able to recieve
|
||||
However, a <code>BroadcastReceiver</code> that is registered to receive system intents is still able to receive
|
||||
other intents from a third-party application, so it should check that the intent received has the expected action.
|
||||
Otherwise, a third-party application could impersonate the system this way and cause unintended behaviour, such as a denial of service.
|
||||
Otherwise, a third-party application could impersonate the system this way and cause unintended behavior, such as a denial of service.
|
||||
</p>
|
||||
</overview>
|
||||
|
||||
<example>
|
||||
<p>In the following code, the <code>ShutdownReceiver</code> initiates a shutdown procedure upon receiving an Intent,
|
||||
<p>In the following code, the <code>ShutdownReceiver</code> initiates a shutdown procedure upon receiving an intent,
|
||||
without checking that the received action is indeed <code>ACTION_SHUTDOWN</code>. This allows third-party applications to
|
||||
send explicit intents to this receiver to cause a denial of service.</p>
|
||||
<sample src="Bad.java" />
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
category: newQuery
|
||||
---
|
||||
* A new query "Improper Verification of Intent by Broadcast Receiver" (`java/improper-intent-verification`) has been added.
|
||||
This query finds instances of Android `BroadcastReceiver`s that don't verify the action string of received Intents when registered
|
||||
This query finds instances of Android `BroadcastReceiver`s that don't verify the action string of received intents when registered
|
||||
to receive system intents.
|
||||
Reference in New Issue
Block a user