Skip to content

(Rebased) Java android remote source#4542

Merged
aschackmull merged 9 commits intogithub:mainfrom
smowton:java-android-remote-source
Nov 3, 2020
Merged

(Rebased) Java android remote source#4542
aschackmull merged 9 commits intogithub:mainfrom
smowton:java-android-remote-source

Conversation

@smowton
Copy link
Contributor

@smowton smowton commented Oct 23, 2020

Just a rebased version of #3812 to make reviewing easier; direct all comments over there.

IntentGetExtraMethodAccess() {
exists(AndroidComponent ac |
this.getEnclosingCallable().getDeclaringType() = ac and
ac.isExported() and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we push this isExported() filter right into AndroidIntentInput, since that seems like the point where we know whether the source is dangerous or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the the isExported() check to AndroidIntentInput.

Comment on lines 343 to 352
private class AndroidIntentExtraSource extends RemoteFlowSource {
AndroidIntentExtraSource() {
exists(AndroidIntentInput inode |
this.asExpr() = inode.asExpr() or
this.asExpr() = inode.asParameter().getAnAccess()
)
}

override string getSourceType() { result = "Android intent extra" }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary -- once AndroidIntentInput is reduced to only inputs of exported classes, we can simply have that class extend RemoteFlowSource

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not required once AndroidIntentInput is reduced to only inputs of exported classes. Changed AndroidIntentInput to extend RemoteFlowSource.

this.getMethod().getDeclaringType() instanceof TypeIntent
)
or
this.getMethod().getName().regexpMatch("get\\w+") and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split these two (get***Extra and the Bundle getters), since they're pretty unrelated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the AndroidIntentInput change, only Bundle getters modelled in GetBundleExtraMethodAccess are required as the additional taint step.

this.getEnclosingCallable().getDeclaringType() = ac and
ac.isExported() and
this.getMethod().getName().regexpMatch("get\\w+Extra") and
this.getMethod().getDeclaringType() instanceof TypeIntent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has conveying taint from the Intent to the Bundle yielded by getExtra gone missing? I'm seeing steps for intent -> getStringExtra and for Bundle -> getString but not for intent -> getExtra -> Bundle -> getString?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested all flow combinations including intent -> getExtras -> Bundle -> getString and the query seems to work as expected.

Do I still miss something?

@joefarebrother
Copy link
Contributor

@luchua-bc Regarding your question on TaintPreservingCallable on the original PR, where were you trying to define it? Note that if it was outside of FlowSteps.qll (which is recommended), you need to ensure that the Frameworks module in FlowSteps imports it, to make the definition visible to all queries.

Also note that getExtra methods on Intent are already modelled in android.Intent.qll, so only the methods on Bundle are necassary.

@luchua-bc
Copy link
Contributor

Thanks @joefarebrother for reviewing the PR. I'm trying to detect a pattern like the following:

public class UnsafeAndroidActivity extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		String thisUrl = bundle.getString("url");
		WebView wv = (WebView) findViewById(-1);
		wv.loadUrl(thisUrl);
	}
}

The flow is getIntent() -> intent -> getExtras() -> bundle -> getString("url").

I thought we must put new TaintPreservingCallable implementations like BundleExtraTaintPreservingCallable in FlowSteps.qll so that all queries can use them. What's the desired location for BundleExtraTaintPreservingCallable?

Thanks,
@luchua-bc

@luchua-bc
Copy link
Contributor

luchua-bc commented Oct 28, 2020

Added TaintPreservingCallable implementation to java/ql/src/semmle/code/java/frameworks/android/Android.qll instead of FlowSteps.qll

@aschackmull aschackmull merged commit 3f298f3 into github:main Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants