|
30 | 30 | import android.autofillservice.cts.commontests.AbstractLoginActivityTestCase; |
31 | 31 | import android.autofillservice.cts.testcore.CannedFillResponse; |
32 | 32 | import android.autofillservice.cts.testcore.Visitor; |
| 33 | +import android.graphics.drawable.Icon; |
33 | 34 | import android.platform.test.annotations.AppModeFull; |
| 35 | +import android.platform.test.annotations.AsbSecurityTest; |
34 | 36 | import android.service.autofill.BatchUpdates; |
35 | 37 | import android.service.autofill.CharSequenceTransformation; |
36 | 38 | import android.service.autofill.CustomDescription; |
@@ -97,6 +99,63 @@ private void testCustomDescription( |
97 | 99 | sReplier.getNextSaveRequest(); |
98 | 100 | } |
99 | 101 |
|
| 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 | + |
100 | 159 | @Test |
101 | 160 | public void testSanitizationBeforeBatchUpdates() throws Exception { |
102 | 161 | enableService(); |
|
0 commit comments