Skip to content

Commit e94b0a7

Browse files
Tim YuAndroid (Google) Code Review
authored andcommitted
Merge "[RESTRICT AUTOMERGE] Autofill add STS tests to guard against RemoteView spills" into udc-dev
2 parents be2061f + 758c857 commit e94b0a7

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

tests/autofillservice/src/android/autofillservice/cts/saveui/CustomDescriptionTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
import android.autofillservice.cts.commontests.AbstractLoginActivityTestCase;
3131
import android.autofillservice.cts.testcore.CannedFillResponse;
3232
import android.autofillservice.cts.testcore.Visitor;
33+
import android.graphics.drawable.Icon;
3334
import android.platform.test.annotations.AppModeFull;
35+
import android.platform.test.annotations.AsbSecurityTest;
3436
import android.service.autofill.BatchUpdates;
3537
import android.service.autofill.CharSequenceTransformation;
3638
import android.service.autofill.CustomDescription;
@@ -97,6 +99,63 @@ private void testCustomDescription(
9799
sReplier.getNextSaveRequest();
98100
}
99101

102+
@Test
103+
@AsbSecurityTest(cveBugId = 286235483)
104+
public void testRemoteViewsDoNotSpill() throws Exception {
105+
enableService();
106+
final RemoteViews regularPresentation = newTemplate(R.layout.two_horizontal_text_fields);
107+
RemoteViews badPresentation = newTemplate(R.layout.two_horizontal_text_fields);
108+
// Try to access a resource that is not owned by the user
109+
// In this case, the URI doesn't exist
110+
badPresentation.setImageViewIcon(
111+
R.id.icon,
112+
Icon.createWithContentUri("content://10@com.android.contacts/display_photo/1"));
113+
badPresentation.setTextViewText(R.id.first, "do not display");
114+
115+
sReplier.addResponse(
116+
new CannedFillResponse.Builder()
117+
.setRequiredSavableIds(SAVE_DATA_TYPE_GENERIC, ID_USERNAME)
118+
.setSaveInfoVisitor(
119+
(contexts, builder) -> {
120+
final AutofillId usernameId =
121+
findAutofillIdByResourceId(
122+
contexts.get(0), ID_USERNAME);
123+
124+
// Validator for sanitization
125+
final Validator validCondition =
126+
new RegexValidator(
127+
usernameId, Pattern.compile("hello"));
128+
final CustomDescription customDescription =
129+
new CustomDescription.Builder(regularPresentation)
130+
.batchUpdate(
131+
validCondition,
132+
new BatchUpdates.Builder()
133+
.updateTemplate(badPresentation)
134+
.build())
135+
.build();
136+
137+
builder.addSanitizer(
138+
new TextValueSanitizer(
139+
Pattern.compile("world"), "hello"),
140+
usernameId)
141+
.setCustomDescription(customDescription);
142+
})
143+
.build());
144+
145+
// Trigger autofill with custom description
146+
mActivity.onPassword(View::requestFocus);
147+
148+
// Wait for onFill() before proceeding.
149+
sReplier.getNextFillRequest();
150+
151+
// Trigger save.
152+
mActivity.onUsername((v) -> v.setText("world"));
153+
mActivity.onPassword((v) -> v.setText(LoginActivity.BACKDOOR_PASSWORD_SUBSTRING));
154+
mActivity.tapLogin();
155+
156+
mUiBot.assertSaveNotShowing(1);
157+
}
158+
100159
@Test
101160
public void testSanitizationBeforeBatchUpdates() throws Exception {
102161
enableService();

0 commit comments

Comments
 (0)