From 52f9039d5cc775a02dab90492cca98850a82872a Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Wed, 14 Apr 2021 15:51:37 +0800 Subject: [PATCH] Prevent HTML Injection on the Device Admin request screen The root issue is that CharSequence is an interface. String implements that interface, however, Spanned class too which is a rich text format that can store HTML code. The solution is enforce to use String type which won't include any HTML function. Test: Rebuilt apk and see the string without HTML style. Bug: 179042963 Change-Id: I53b460b12da918e022d2f2934f114d205dbaadb0 Merged-In: I53b460b12da918e022d2f2934f114d205dbaadb0 (cherry picked from commit 0bf3c98b2f325f70d5492a7c7ade16951a802600) --- .../specialaccess/deviceadmin/DeviceAdminAdd.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java index 8b06975bc06..bc417860a20 100644 --- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java +++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminAdd.java @@ -102,7 +102,7 @@ public class DeviceAdminAdd extends Activity { DevicePolicyManager mDPM; AppOpsManager mAppOps; DeviceAdminInfo mDeviceAdmin; - CharSequence mAddMsgText; + String mAddMsgText; String mProfileOwnerName; ImageView mAdminIcon; @@ -274,7 +274,11 @@ public class DeviceAdminAdd extends Activity { } } - mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION); + final CharSequence addMsgCharSequence = getIntent().getCharSequenceExtra( + DevicePolicyManager.EXTRA_ADD_EXPLANATION); + if (addMsgCharSequence != null) { + mAddMsgText = addMsgCharSequence.toString(); + } if (mAddingProfileOwner) { // If we're trying to add a profile owner and user setup hasn't completed yet, no @@ -622,7 +626,7 @@ public class DeviceAdminAdd extends Activity { } catch (Resources.NotFoundException e) { mAdminDescription.setVisibility(View.GONE); } - if (mAddMsgText != null) { + if (!TextUtils.isEmpty(mAddMsgText)) { mAddMsg.setText(mAddMsgText); mAddMsg.setVisibility(View.VISIBLE); } else {