|
| 1 | +/** Provides classes to reason about Android Intent redirect vulnerabilities. */ |
| 2 | + |
| 3 | +import java |
| 4 | +private import semmle.code.java.controlflow.Guards |
| 5 | +private import semmle.code.java.dataflow.DataFlow |
| 6 | +private import semmle.code.java.dataflow.ExternalFlow |
| 7 | +private import semmle.code.java.frameworks.android.Intent |
| 8 | + |
| 9 | +/** |
| 10 | + * A sink for Intent redirection vulnerabilities in Android, |
| 11 | + * that is, method calls that start Android components (like activities or services). |
| 12 | + */ |
| 13 | +abstract class IntentRedirectionSink extends DataFlow::Node { } |
| 14 | + |
| 15 | +/** A sanitizer for data used to start an Android component. */ |
| 16 | +abstract class IntentRedirectionSanitizer extends DataFlow::Node { } |
| 17 | + |
| 18 | +/** |
| 19 | + * A unit class for adding additional taint steps. |
| 20 | + * |
| 21 | + * Extend this class to add additional taint steps that should apply to `IntentRedirectionConfiguration`. |
| 22 | + */ |
| 23 | +class IntentRedirectionAdditionalTaintStep extends Unit { |
| 24 | + /** |
| 25 | + * Holds if the step from `node1` to `node2` should be considered a taint |
| 26 | + * step for the `IntentRedirectionConfiguration` configuration. |
| 27 | + */ |
| 28 | + abstract predicate step(DataFlow::Node node1, DataFlow::Node node2); |
| 29 | +} |
| 30 | + |
| 31 | +private class DefaultIntentRedirectionSinkModel extends SinkModelCsv { |
| 32 | + override predicate row(string row) { |
| 33 | + row = |
| 34 | + [ |
| 35 | + "android.app;Activity;true;bindService;;;Argument[0];intent-start", |
| 36 | + "android.app;Activity;true;bindServiceAsUser;;;Argument[0];intent-start", |
| 37 | + "android.app;Activity;true;startActivityAsCaller;;;Argument[0];intent-start", |
| 38 | + "android.app;Activity;true;startActivityForResult;(Intent,int);;Argument[0];intent-start", |
| 39 | + "android.app;Activity;true;startActivityForResult;(Intent,int,Bundle);;Argument[0];intent-start", |
| 40 | + "android.app;Activity;true;startActivityForResult;(String,Intent,int,Bundle);;Argument[1];intent-start", |
| 41 | + "android.app;Activity;true;startActivityForResultAsUser;;;Argument[0];intent-start", |
| 42 | + "android.content;Context;true;startActivities;;;Argument[0];intent-start", |
| 43 | + "android.content;Context;true;startActivity;;;Argument[0];intent-start", |
| 44 | + "android.content;Context;true;startActivityAsUser;;;Argument[0];intent-start", |
| 45 | + "android.content;Context;true;startActivityFromChild;;;Argument[1];intent-start", |
| 46 | + "android.content;Context;true;startActivityFromFragment;;;Argument[1];intent-start", |
| 47 | + "android.content;Context;true;startActivityIfNeeded;;;Argument[0];intent-start", |
| 48 | + "android.content;Context;true;startForegroundService;;;Argument[0];intent-start", |
| 49 | + "android.content;Context;true;startService;;;Argument[0];intent-start", |
| 50 | + "android.content;Context;true;startServiceAsUser;;;Argument[0];intent-start", |
| 51 | + "android.content;Context;true;sendBroadcast;;;Argument[0];intent-start", |
| 52 | + "android.content;Context;true;sendBroadcastAsUser;;;Argument[0];intent-start", |
| 53 | + "android.content;Context;true;sendBroadcastWithMultiplePermissions;;;Argument[0];intent-start", |
| 54 | + "android.content;Context;true;sendStickyBroadcast;;;Argument[0];intent-start", |
| 55 | + "android.content;Context;true;sendStickyBroadcastAsUser;;;Argument[0];intent-start", |
| 56 | + "android.content;Context;true;sendStickyOrderedBroadcast;;;Argument[0];intent-start", |
| 57 | + "android.content;Context;true;sendStickyOrderedBroadcastAsUser;;;Argument[0];intent-start" |
| 58 | + ] |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +/** Default sink for Intent redirection vulnerabilities. */ |
| 63 | +private class DefaultIntentRedirectionSink extends IntentRedirectionSink { |
| 64 | + DefaultIntentRedirectionSink() { sinkNode(this, "intent-start") } |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * A default sanitizer for nodes dominated by calls to `ComponentName.getPackageName` |
| 69 | + * or `ComponentName.getClassName`. These are used to check whether the origin or destination |
| 70 | + * components are trusted. |
| 71 | + */ |
| 72 | +private class DefaultIntentRedirectionSanitizer extends IntentRedirectionSanitizer { |
| 73 | + DefaultIntentRedirectionSanitizer() { |
| 74 | + exists(MethodAccess ma, Method m, Guard g, boolean branch | |
| 75 | + ma.getMethod() = m and |
| 76 | + m.getDeclaringType() instanceof TypeComponentName and |
| 77 | + m.hasName(["getPackageName", "getClassName"]) and |
| 78 | + g.isEquality(ma, _, branch) and |
| 79 | + g.controls(this.asExpr().getBasicBlock(), branch) |
| 80 | + ) |
| 81 | + } |
| 82 | +} |
0 commit comments