Skip to content

Commit 3279205

Browse files
Tim YuAndroid Build Coastguard Worker
authored andcommitted
[RESTRICT AUTOMERGE] Check permission of Autofill icon URIs
* SaveUI's template * Inline Suggestions slices Fixes: b/286235483 Fixes: b/292104015 Test: atest CtsAutoFillServiceTestCases (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:046cc236501e4f12bfc4a26948b5b6b76695afb9) Merged-In: I48879174664b70ced90492bb0991dc91cbf89b79 Change-Id: I48879174664b70ced90492bb0991dc91cbf89b79
1 parent e23bf10 commit 3279205

3 files changed

Lines changed: 58 additions & 11 deletions

File tree

services/autofill/java/com/android/server/autofill/Helper.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import android.app.assist.AssistStructure;
2424
import android.app.assist.AssistStructure.ViewNode;
2525
import android.app.assist.AssistStructure.WindowNode;
26+
import android.app.slice.Slice;
27+
import android.app.slice.SliceItem;
2628
import android.content.ComponentName;
29+
import android.graphics.drawable.Icon;
2730
import android.metrics.LogMaker;
2831
import android.service.autofill.Dataset;
2932
import android.service.autofill.InternalSanitizer;
@@ -47,7 +50,6 @@
4750
import java.util.Arrays;
4851
import java.util.concurrent.atomic.AtomicBoolean;
4952

50-
5153
public final class Helper {
5254

5355
private static final String TAG = "AutofillHelper";
@@ -85,7 +87,7 @@ private static boolean checkRemoteViewUriPermissions(
8587
final AtomicBoolean permissionsOk = new AtomicBoolean(true);
8688

8789
rView.visitUris(uri -> {
88-
int uriOwnerId = android.content.ContentProvider.getUserIdFromUri(uri);
90+
int uriOwnerId = android.content.ContentProvider.getUserIdFromUri(uri, userId);
8991
boolean allowed = uriOwnerId == userId;
9092
permissionsOk.set(allowed && permissionsOk.get());
9193
});
@@ -117,6 +119,48 @@ private static boolean checkRemoteViewUriPermissions(
117119
return (ok ? rView : null);
118120
}
119121

122+
/**
123+
* Checks the URI permissions of the icon in the slice, to see if the current userId is able to
124+
* access it.
125+
*
126+
* <p>Returns null if slice contains user inaccessible icons
127+
*
128+
* <p>TODO: instead of returning a null Slice when the current userId cannot access an icon,
129+
* return a reconstructed Slice without the icons. This is currently non-trivial since there are
130+
* no public methods to generically add SliceItems to Slices
131+
*/
132+
public static @Nullable Slice sanitizeSlice(Slice slice) {
133+
if (slice == null) {
134+
return null;
135+
}
136+
137+
int userId = ActivityManager.getCurrentUser();
138+
139+
// Recontruct the Slice, filtering out bad icons
140+
for (SliceItem sliceItem : slice.getItems()) {
141+
if (!sliceItem.getFormat().equals(SliceItem.FORMAT_IMAGE)) {
142+
// Not an image slice
143+
continue;
144+
}
145+
146+
Icon icon = sliceItem.getIcon();
147+
if (icon.getType() != Icon.TYPE_URI
148+
&& icon.getType() != Icon.TYPE_URI_ADAPTIVE_BITMAP) {
149+
// No URIs to sanitize
150+
continue;
151+
}
152+
153+
int iconUriId = android.content.ContentProvider.getUserIdFromUri(icon.getUri(), userId);
154+
155+
if (iconUriId != userId) {
156+
Slog.w(TAG, "sanitizeSlice() user: " + userId + " cannot access icons in Slice");
157+
return null;
158+
}
159+
}
160+
161+
return slice;
162+
}
163+
120164

121165
@Nullable
122166
static AutofillId[] toArray(@Nullable ArraySet<AutofillId> set) {

services/autofill/java/com/android/server/autofill/ui/RemoteInlineSuggestionViewConnector.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.util.Slog;
2828

2929
import com.android.server.LocalServices;
30+
import com.android.server.autofill.Helper;
3031
import com.android.server.autofill.RemoteInlineSuggestionRenderService;
3132
import com.android.server.inputmethod.InputMethodManagerInternal;
3233

@@ -39,12 +40,9 @@
3940
final class RemoteInlineSuggestionViewConnector {
4041
private static final String TAG = RemoteInlineSuggestionViewConnector.class.getSimpleName();
4142

42-
@Nullable
43-
private final RemoteInlineSuggestionRenderService mRemoteRenderService;
44-
@NonNull
45-
private final InlinePresentation mInlinePresentation;
46-
@Nullable
47-
private final IBinder mHostInputToken;
43+
@Nullable private final RemoteInlineSuggestionRenderService mRemoteRenderService;
44+
@NonNull private final InlinePresentation mInlinePresentation;
45+
@Nullable private final IBinder mHostInputToken;
4846
private final int mDisplayId;
4947
private final int mUserId;
5048
private final int mSessionId;
@@ -78,8 +76,12 @@ final class RemoteInlineSuggestionViewConnector {
7876
*
7977
* @return true if the call is made to the remote renderer service, false otherwise.
8078
*/
81-
public boolean renderSuggestion(int width, int height,
82-
@NonNull IInlineSuggestionUiCallback callback) {
79+
public boolean renderSuggestion(
80+
int width, int height, @NonNull IInlineSuggestionUiCallback callback) {
81+
if (Helper.sanitizeSlice(mInlinePresentation.getSlice()) == null) {
82+
if (sDebug) Slog.d(TAG, "Skipped rendering inline suggestion.");
83+
return false;
84+
}
8385
if (mRemoteRenderService != null) {
8486
if (sDebug) Slog.d(TAG, "Request to recreate the UI");
8587
mRemoteRenderService.renderSuggestion(callback, mInlinePresentation, width, height,

services/autofill/java/com/android/server/autofill/ui/SaveUi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ private boolean applyCustomDescription(@NonNull Context context, @NonNull View s
427427
}
428428
final BatchUpdates batchUpdates = pair.second;
429429
// First apply the updates...
430-
final RemoteViews templateUpdates = batchUpdates.getUpdates();
430+
final RemoteViews templateUpdates =
431+
Helper.sanitizeRemoteView(batchUpdates.getUpdates());
431432
if (templateUpdates != null) {
432433
if (sDebug) Slog.d(TAG, "Applying template updates for batch update #" + i);
433434
templateUpdates.reapply(context, customSubtitleView);

0 commit comments

Comments
 (0)