|
5 | 5 | import java |
6 | 6 | import semmle.code.java.dataflow.ExternalFlow |
7 | 7 | import semmle.code.xml.AndroidManifest |
| 8 | +private import semmle.code.java.dataflow.ExternalFlow |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Gets a transitive superType avoiding magic optimisation |
@@ -202,3 +203,59 @@ private class ContentProviderSourceModels extends SourceModelCsv { |
202 | 203 | ] |
203 | 204 | } |
204 | 205 | } |
| 206 | + |
| 207 | +/** Interface for classes whose instances can be written to and restored from a Parcel. */ |
| 208 | +class TypeParcelable extends Interface { |
| 209 | + TypeParcelable() { this.hasQualifiedName("android.os", "Parcelable") } |
| 210 | +} |
| 211 | + |
| 212 | +/** |
| 213 | + * A method that overrides `android.os.Parcelable.Creator.createFromParcel`. |
| 214 | + */ |
| 215 | +class CreateFromParcelMethod extends Method { |
| 216 | + CreateFromParcelMethod() { |
| 217 | + this.hasName("createFromParcel") and |
| 218 | + this.getEnclosingCallable().getDeclaringType().getASupertype*() instanceof TypeParcelable |
| 219 | + } |
| 220 | +} |
| 221 | + |
| 222 | +private class TaintPropagationModels extends SummaryModelCsv { |
| 223 | + override predicate row(string s) { |
| 224 | + // BaseBundle getters |
| 225 | + s = |
| 226 | + "android.os;BaseBundle;true;get" + ["Boolean", "Double", "Int", "Long", "String"] + |
| 227 | + ["", "Array"] + ";;;Argument[-1];ReturnValue;taint" |
| 228 | + or |
| 229 | + // Bundle getters |
| 230 | + s = |
| 231 | + "android.os;Bundle;true;get" + |
| 232 | + [ |
| 233 | + "Binder", "Bundle", "Byte", "ByteArray", "Char", "CharArray", "CharSequence", |
| 234 | + "CharSequenceArray", "CharSequenceArrayList", "Float", "FloatArray", "IntegerArrayList", |
| 235 | + "Parcelable", "ParcelableArray", "ParcelableArrayList", "Serializable", "Short", |
| 236 | + "ShortArray", "Size", "SizeF", "SparseParcelableArray", "StringArrayList" |
| 237 | + ] + ";;;Argument[-1];ReturnValue;taint" |
| 238 | + or |
| 239 | + // Intent readers that return their value |
| 240 | + s = |
| 241 | + "android.os;Parcel;false;read" + |
| 242 | + [ |
| 243 | + "Array", "ArrayList", "Boolean", "Bundle", "Byte", "Double", "FileDescriptor", "Float", |
| 244 | + "HashMap", "Int", "Long", "Parcelable", "ParcelableArray", "PersistableBundle", |
| 245 | + "Serializable", "Size", "SizeF", "SparseArray", "SparseBolleanArray", "String", |
| 246 | + "StrongBinder", "TypedObject", "Value" |
| 247 | + ] + ";;;Argument[-1];ReturnValue;taint" |
| 248 | + or |
| 249 | + // Intent readers that write to an existing object |
| 250 | + s = |
| 251 | + "android.os;Parcel;false;read" + |
| 252 | + [ |
| 253 | + "BinderArray", "BinderList", "BooleanArray", "ByteArray", "CharArray", "DoubleArray", |
| 254 | + "FloatArray", "IntArray", "List", "LongArray", "Map", "ParcelableList", "StringArray", |
| 255 | + "StringList", "TypedArray", "TypedList" |
| 256 | + ] + ";;;Argument[-1];Argument[0];taint" |
| 257 | + or |
| 258 | + // One Intent method that aliases an argument to a return value |
| 259 | + s = "android.os;Parcel;false;readParcelableList;;;Argument[0];ReturnValue;value" |
| 260 | + } |
| 261 | +} |
0 commit comments