Adress reveiw comments - make use of existing ql libraries

This commit is contained in:
Joe Farebrother
2022-04-28 14:14:02 +01:00
parent 9d048e78af
commit 320c671b73
2 changed files with 12 additions and 21 deletions

View File

@@ -2,13 +2,12 @@
import java import java
import semmle.code.java.dataflow.DataFlow import semmle.code.java.dataflow.DataFlow
import semmle.code.xml.AndroidManifest
import semmle.code.java.frameworks.android.Intent
/** An `onReceive` method of a `BroadcastReceiver` */ /** An `onReceive` method of a `BroadcastReceiver` */
private class OnReceiveMethod extends Method { private class OnReceiveMethod extends Method {
OnReceiveMethod() { OnReceiveMethod() { this.getASourceOverriddenMethod*() instanceof AndroidReceiveIntentMethod }
this.getASourceOverriddenMethod*()
.hasQualifiedName("android.content", "BroadcastReceiver", "onReceive")
}
/** Gets the parameter 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) } Parameter getIntentParameter() { result = this.getParameter(1) }
@@ -31,7 +30,7 @@ private class VerifiedIntentConfig extends DataFlow::Configuration {
} }
/** An `onReceive` method that doesn't verify the action of the intent it receives. */ /** An `onReceive` method that doesn't verify the action of the intent it receives. */
class UnverifiedOnReceiveMethod extends OnReceiveMethod { private class UnverifiedOnReceiveMethod extends OnReceiveMethod {
UnverifiedOnReceiveMethod() { UnverifiedOnReceiveMethod() {
not any(VerifiedIntentConfig c).hasFlow(DataFlow::parameterNode(this.getIntentParameter()), _) not any(VerifiedIntentConfig c).hasFlow(DataFlow::parameterNode(this.getIntentParameter()), _)
} }
@@ -62,21 +61,18 @@ class SystemActionName extends Top {
SystemActionName() { SystemActionName() {
name = getASystemActionName() and name = getASystemActionName() and
( (
this.(StringLiteral).getValue() = "android.intent.action." + name this.(CompileTimeConstantExpr).getStringValue() = "android.intent.action." + name
or or
this.(FieldRead).getField().hasQualifiedName("android.content", "Intent", "ACTION_" + name) this.(FieldRead).getField().hasQualifiedName("android.content", "Intent", "ACTION_" + name)
or or
this.(XMLAttribute).getValue() = "android.intent.action." + name this.(AndroidActionXmlElement).getActionName() = "android.intent.action." + name
) )
} }
/** Gets the name of the system intent that this expression or attribute represents. */ /** Gets the name of the system intent that this expression or attribute represents. */
string getName() { result = name } string getName() { result = name }
override string toString() { override string toString() { result = [this.(Expr).toString(), this.(XMLAttribute).toString()] }
result =
[this.(StringLiteral).toString(), this.(FieldRead).toString(), this.(XMLAttribute).toString()]
}
} }
/** A call to `Context.registerReceiver` */ /** A call to `Context.registerReceiver` */
@@ -138,17 +134,12 @@ private predicate registeredUnverifiedSystemReceiver(
/** Holds if the XML element `rec` declares a receiver `orm` to receive the system action named `sa` that doesn't verify intents it receives. */ /** 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( private predicate xmlUnverifiedSystemReceiver(
XMLElement rec, UnverifiedOnReceiveMethod orm, SystemActionName sa AndroidReceiverXmlElement rec, UnverifiedOnReceiveMethod orm, SystemActionName sa
) { ) {
exists(XMLElement filter, XMLElement action, Class ormty | exists(Class ormty |
rec.hasName("receiver") and
filter.hasName("intent-filter") and
action.hasName("action") and
filter = rec.getAChild() and
action = filter.getAChild() and
ormty = orm.getDeclaringType() and ormty = orm.getDeclaringType() and
rec.getAttribute("name").getValue() = ["." + ormty.getName(), ormty.getQualifiedName()] and rec.getComponentName() = ["." + ormty.getName(), ormty.getQualifiedName()] and
action.getAttribute("name") = sa rec.getAnIntentFilterElement().getAnActionElement() = sa
) )
} }

View File

@@ -15,5 +15,5 @@ import semmle.code.java.security.ImproperIntentVerificationQuery
from Top reg, Method orm, SystemActionName sa from Top reg, Method orm, SystemActionName sa
where unverifiedSystemReceiver(reg, orm, sa) where unverifiedSystemReceiver(reg, orm, sa)
select orm, "This reciever doesn't verify intents it recieves, and is registered $@ to recieve $@.", select orm, "This reciever doesn't verify intents it receives, and is registered $@ to receive $@.",
reg, "here", sa, "the system action " + sa.getName() reg, "here", sa, "the system action " + sa.getName()