Skip to content

MASTG-DEMO-0159: Sensitive Views Without Accessibility Data Sensitivity

Download MASTG-DEMO-0159 APK Open MASTG-DEMO-0159 Folder Build MASTG-DEMO-0159 APK

Sample

The sample creates a login and payment form with views that handle sensitive data, each using a different accessibility data sensitivity configuration. It does so by using Kotlin and the Android View APIs (instead of Android layout XML).

  1. Username field: isn't marked as accessibility data sensitive.
  2. Password field: is explicitly marked as accessibility data sensitive using setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES).
  3. One-time code field: sets filterTouchesWhenObscured, which implies accessibility data sensitivity.
  4. Payment container: a LinearLayout that is explicitly marked as accessibility data sensitive using setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES). It contains two views:
    • Card number field: keeps the default value, ACCESSIBILITY_DATA_SENSITIVE_AUTO, so it inherits the protection from the payment container.
    • Confirm Payment button: explicitly disables the protection using setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_NO), which overrides the value inherited from the payment container.
  5. Cancel button: is outside the payment container and keeps the default value, ACCESSIBILITY_DATA_SENSITIVE_AUTO. It doesn't handle sensitive data, so it isn't protected.

Marking a view as accessibility data sensitive only restricts accessibility services that aren't declared as accessibility tools. Accessibility tools, such as screen readers, can still read and interact with all of these views (see "Accessibility Tools" in Accessibility Data Sensitivity).

When you tap Start, the app shows the form at the bottom of the screen and lists the value returned by isAccessibilityDataSensitive for each view. Tapping Confirm Payment or Cancel closes the form and shows a confirmation message.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package org.owasp.mastestapp

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.text.InputType
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.widget.Button
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.Toast

// SUMMARY: This sample demonstrates views that handle sensitive data with and without accessibility data sensitivity,
// set explicitly, inherited from a parent, implied by filterTouchesWhenObscured, or explicitly disabled.

class MastgTest(private val context: Context) {

    val shouldRunInMainThread = true

    private val formTag = "mastg-demo-form"

    fun mastgTest(): String {
        val r = DemoResults("0x01")

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
            r.add(Status.ERROR, "Accessibility data sensitivity requires Android 14 (API level 34) or higher.")
            return r.toJson()
        }

        val form = LinearLayout(context).apply {
            tag = formTag
            orientation = LinearLayout.VERTICAL
            setBackgroundColor(Color.rgb(48, 48, 48))
            setOnApplyWindowInsetsListener { view, insets ->
                val bottom = insets.getInsets(WindowInsets.Type.systemBars() or WindowInsets.Type.ime()).bottom
                view.setPadding(48, 32, 48, 32 + bottom)
                insets
            }
        }

        // FAIL: [MASTG-TEST-0403] The username field handles credentials but isn't marked as accessibility data sensitive.
        val usernameField = createField("Username", InputType.TYPE_CLASS_TEXT)
        form.addView(usernameField)

        // PASS: [MASTG-TEST-0403] The password field is explicitly marked as accessibility data sensitive.
        val passwordField = createField("Password", InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
        passwordField.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES)
        form.addView(passwordField)

        // PASS: [MASTG-TEST-0403] The one-time code field uses filterTouchesWhenObscured, which implies accessibility data sensitivity.
        val otpField = createField("One-time code", InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_PASSWORD)
        otpField.filterTouchesWhenObscured = true
        form.addView(otpField)

        // PASS: [MASTG-TEST-0403] The payment container is marked as accessibility data sensitive, so its children inherit the protection.
        val paymentContainer = LinearLayout(context).apply {
            orientation = LinearLayout.VERTICAL
        }
        paymentContainer.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES)

        val cardField = createField("Card number", InputType.TYPE_CLASS_NUMBER)
        paymentContainer.addView(cardField)

        // FAIL: [MASTG-TEST-0403] The payment confirmation button explicitly disables the protection inherited from its parent.
        val confirmButton = Button(context).apply {
            text = "Confirm Payment"
            setOnClickListener { closeForm(form, "Payment confirmed.") }
        }
        confirmButton.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_NO)
        paymentContainer.addView(confirmButton)

        form.addView(paymentContainer)

        val cancelButton = Button(context).apply {
            text = "Cancel"
            setOnClickListener { closeForm(form, "Payment cancelled.") }
        }
        form.addView(cancelButton)

        (context as? Activity)?.let { activity ->
            val root = activity.findViewById<ViewGroup>(android.R.id.content)
            root.findViewWithTag<View>(formTag)?.let { root.removeView(it) }
            root.addView(
                form,
                FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM
                )
            )
            form.requestApplyInsets()
        }

        listOf(
            "Username field" to usernameField,
            "Password field" to passwordField,
            "One-time code field" to otpField,
            "Card number field" to cardField,
            "Confirm Payment button" to confirmButton
        ).forEach { (name, view) ->
            val sensitive = view.isAccessibilityDataSensitive()
            r.add(
                if (sensitive) Status.PASS else Status.FAIL,
                "$name: isAccessibilityDataSensitive=$sensitive"
            )
        }

        return r.toJson()
    }

    private fun closeForm(form: View, message: String) {
        (form.parent as? ViewGroup)?.removeView(form)
        Log.i("MASTG-DEMO", message)
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
    }

    private fun createField(hintText: String, type: Int): EditText {
        return EditText(context).apply {
            hint = hintText
            inputType = type
            setTextColor(Color.WHITE)
            setHintTextColor(Color.LTGRAY)
        }
    }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package org.owasp.mastestapp;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.savedstate.serialization.ClassDiscriminatorModeKt;
import kotlin.Metadata;
import kotlin.Pair;
import kotlin.TuplesKt;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.internal.Intrinsics;

/* JADX INFO: compiled from: MastgTest.kt */
/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0007\u0018\u00002\u00020\u0001B\u000f\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0004\b\u0004\u0010\u0005J\u0006\u0010\f\u001a\u00020\u000bJ\u0018\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u000bH\u0002J\u0018\u0010\u0012\u001a\u00020\u00132\u0006\u0010\u0014\u001a\u00020\u000b2\u0006\u0010\u0015\u001a\u00020\u0016H\u0002R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0006\u001a\u00020\u0007X\u0086D¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u000e\u0010\n\u001a\u00020\u000bX\u0082D¢\u0006\u0002\n\u0000Ê\u0001\f\b\u0018\u0012\b\b\u0019\u0012\u0004\b\u0003\u0010\u0000¨\u0006\u0017"}, d2 = {"Lorg/owasp/mastestapp/MastgTest;", "", "context", "Landroid/content/Context;", "<init>", "(Landroid/content/Context;)V", "shouldRunInMainThread", "", "getShouldRunInMainThread", "()Z", "formTag", "", "mastgTest", "closeForm", "", "form", "Landroid/view/View;", "message", "createField", "Landroid/widget/EditText;", "hintText", ClassDiscriminatorModeKt.CLASS_DISCRIMINATOR_KEY, "", "app", "Landroidx/compose/runtime/internal/StabilityInferred;", "parameters"}, k = 1, mv = {2, 4, 0}, xi = 48)
public final class MastgTest {
    public static final int $stable = 8;
    private final Context context;
    private final String formTag;
    private final boolean shouldRunInMainThread;

    public MastgTest(Context context) {
        Intrinsics.checkNotNullParameter(context, "context");
        this.context = context;
        this.shouldRunInMainThread = true;
        this.formTag = "mastg-demo-form";
    }

    public final boolean getShouldRunInMainThread() {
        return this.shouldRunInMainThread;
    }

    public final String mastgTest() {
        DemoResults r = new DemoResults("0x01");
        if (Build.VERSION.SDK_INT < 34) {
            r.add(Status.ERROR, "Accessibility data sensitivity requires Android 14 (API level 34) or higher.");
            return r.toJson();
        }
        final LinearLayout form = new LinearLayout(this.context);
        form.setTag(this.formTag);
        form.setOrientation(1);
        form.setBackgroundColor(Color.rgb(48, 48, 48));
        form.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { // from class: org.owasp.mastestapp.MastgTest$$ExternalSyntheticLambda0
            @Override // android.view.View.OnApplyWindowInsetsListener
            public final WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                return MastgTest.mastgTest$lambda$0$0(view, windowInsets);
            }
        });
        EditText usernameField = createField("Username", 1);
        form.addView(usernameField);
        EditText passwordField = createField("Password", 129);
        passwordField.setAccessibilityDataSensitive(1);
        form.addView(passwordField);
        EditText otpField = createField("One-time code", 18);
        otpField.setFilterTouchesWhenObscured(true);
        form.addView(otpField);
        LinearLayout paymentContainer = new LinearLayout(this.context);
        paymentContainer.setOrientation(1);
        paymentContainer.setAccessibilityDataSensitive(1);
        EditText cardField = createField("Card number", 2);
        paymentContainer.addView(cardField);
        Button confirmButton = new Button(this.context);
        confirmButton.setText("Confirm Payment");
        confirmButton.setOnClickListener(new View.OnClickListener() { // from class: org.owasp.mastestapp.MastgTest$$ExternalSyntheticLambda1
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                MastgTest.mastgTest$lambda$2$0(this.f$0, form, view);
            }
        });
        confirmButton.setAccessibilityDataSensitive(2);
        paymentContainer.addView(confirmButton);
        form.addView(paymentContainer);
        Button button = new Button(this.context);
        button.setText("Cancel");
        button.setOnClickListener(new View.OnClickListener() { // from class: org.owasp.mastestapp.MastgTest$$ExternalSyntheticLambda2
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                MastgTest.mastgTest$lambda$3$0(this.f$0, form, view);
            }
        });
        form.addView(button);
        Context context = this.context;
        Activity activity = context instanceof Activity ? (Activity) context : null;
        if (activity != null) {
            ViewGroup viewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
            View viewFindViewWithTag = viewGroup.findViewWithTag(this.formTag);
            if (viewFindViewWithTag != null) {
                viewGroup.removeView(viewFindViewWithTag);
            }
            viewGroup.addView(form, new FrameLayout.LayoutParams(-1, -2, 80));
            form.requestApplyInsets();
        }
        Iterable<Pair> iterableListOf = CollectionsKt.listOf((Object[]) new Pair[]{TuplesKt.to("Username field", usernameField), TuplesKt.to("Password field", passwordField), TuplesKt.to("One-time code field", otpField), TuplesKt.to("Card number field", cardField), TuplesKt.to("Confirm Payment button", confirmButton)});
        int i = 0;
        for (Pair pair : iterableListOf) {
            String str = (String) pair.component1();
            boolean zIsAccessibilityDataSensitive = ((TextView) pair.component2()).isAccessibilityDataSensitive();
            r.add(zIsAccessibilityDataSensitive ? Status.PASS : Status.FAIL, str + ": isAccessibilityDataSensitive=" + zIsAccessibilityDataSensitive);
            i = i;
            iterableListOf = iterableListOf;
            usernameField = usernameField;
        }
        return r.toJson();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final WindowInsets mastgTest$lambda$0$0(View view, WindowInsets insets) {
        Intrinsics.checkNotNullParameter(view, "view");
        Intrinsics.checkNotNullParameter(insets, "insets");
        int bottom = insets.getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.ime()).bottom;
        view.setPadding(48, 32, 48, bottom + 32);
        return insets;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void mastgTest$lambda$2$0(MastgTest this$0, LinearLayout $form, View it) {
        this$0.closeForm($form, "Payment confirmed.");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void mastgTest$lambda$3$0(MastgTest this$0, LinearLayout $form, View it) {
        this$0.closeForm($form, "Payment cancelled.");
    }

    private final void closeForm(View form, String message) {
        ViewParent parent = form.getParent();
        ViewGroup viewGroup = parent instanceof ViewGroup ? (ViewGroup) parent : null;
        if (viewGroup != null) {
            viewGroup.removeView(form);
        }
        Log.i("MASTG-DEMO", message);
        Toast.makeText(this.context, message, 0).show();
    }

    private final EditText createField(String hintText, int type) {
        EditText editText = new EditText(this.context);
        editText.setHint(hintText);
        editText.setInputType(type);
        editText.setTextColor(-1);
        editText.setHintTextColor(-3355444);
        return editText;
    }
}

Steps

Let's run our semgrep rule against the reverse-engineered code.

../../../../rules/mastg-android-accessibility-data-sensitive.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
rules:
  - id: mastg-android-accessibility-data-sensitive-set
    severity: INFO
    languages:
      - java
    metadata:
      summary: Detects calls to setAccessibilityDataSensitive that mark views as sensitive or keep the automatic behavior (0 = ACCESSIBILITY_DATA_SENSITIVE_AUTO, 1 = ACCESSIBILITY_DATA_SENSITIVE_YES).
    message: "[MASVS-PLATFORM-3] setAccessibilityDataSensitive is used to configure the accessibility data sensitivity of a view"
    patterns:
      - pattern: $VIEW.setAccessibilityDataSensitive($VALUE)
      - pattern-not: $VIEW.setAccessibilityDataSensitive(2)
      - pattern-not: $VIEW.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_NO)

  - id: mastg-android-accessibility-data-sensitive-disabled
    severity: WARNING
    languages:
      - java
    metadata:
      summary: Detects calls to setAccessibilityDataSensitive with ACCESSIBILITY_DATA_SENSITIVE_NO (2), which disables the protection for a view, including protection inherited from its parents.
    message: "[MASVS-PLATFORM-3] setAccessibilityDataSensitive is used to explicitly disable the accessibility data sensitivity of a view"
    pattern-either:
      - pattern: $VIEW.setAccessibilityDataSensitive(2)
      - pattern: $VIEW.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_NO)

  - id: mastg-android-accessibility-data-sensitive-filter-touches
    severity: INFO
    languages:
      - java
    metadata:
      summary: Detects calls to setFilterTouchesWhenObscured, which implies accessibility data sensitivity for views using ACCESSIBILITY_DATA_SENSITIVE_AUTO.
    message: "[MASVS-PLATFORM-3] setFilterTouchesWhenObscured is used, which implies accessibility data sensitivity unless the view sets ACCESSIBILITY_DATA_SENSITIVE_NO"
    pattern: $VIEW.setFilterTouchesWhenObscured(...)

  - id: mastg-android-accessibility-data-sensitive-xml-attribute
    severity: INFO
    languages:
      - xml
    metadata:
      summary: Detects the android:accessibilityDataSensitive attribute in layout XML files.
    message: "[MASVS-PLATFORM-3] android:accessibilityDataSensitive is set to $VALUE"
    pattern: android:accessibilityDataSensitive="$VALUE"

  - id: mastg-android-accessibility-data-sensitive-xml-filter-touches
    severity: INFO
    languages:
      - xml
    metadata:
      summary: Detects the android:filterTouchesWhenObscured attribute in layout XML files, which implies accessibility data sensitivity.
    message: "[MASVS-PLATFORM-3] android:filterTouchesWhenObscured is set to true, which implies accessibility data sensitivity unless the view sets android:accessibilityDataSensitive to false"
    pattern: android:filterTouchesWhenObscured="true"
run.sh
1
2
3
4
#!/bin/bash

# Run semgrep to detect accessibility data sensitivity configurations
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-accessibility-data-sensitive.yaml ./MastgTest_reversed.java --text > output.txt

Observation

The rule reports the calls to setAccessibilityDataSensitive and setFilterTouchesWhenObscured in the reverse-engineered code. In the decompiled code, the constants appear as their integer values: 1 for ACCESSIBILITY_DATA_SENSITIVE_YES and 2 for ACCESSIBILITY_DATA_SENSITIVE_NO.

output.txt
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
┌─────────────────┐
│ 4 Code Findings │
└─────────────────┘

    MastgTest_reversed.java
     ❱ rules.mastg-android-accessibility-data-sensitive-set
          ❰❰ Blocking ❱❱
          [MASVS-PLATFORM-3] setAccessibilityDataSensitive is used to configure the accessibility data
          sensitivity of a view                                                                       

           64┆ passwordField.setAccessibilityDataSensitive(1);

     ❱ rules.mastg-android-accessibility-data-sensitive-filter-touches
          ❰❰ Blocking ❱❱
          [MASVS-PLATFORM-3] setFilterTouchesWhenObscured is used, which implies accessibility data
          sensitivity unless the view sets ACCESSIBILITY_DATA_SENSITIVE_NO                         

           67┆ otpField.setFilterTouchesWhenObscured(true);

     ❱ rules.mastg-android-accessibility-data-sensitive-set
          ❰❰ Blocking ❱❱
          [MASVS-PLATFORM-3] setAccessibilityDataSensitive is used to configure the accessibility data
          sensitivity of a view                                                                       

           71┆ paymentContainer.setAccessibilityDataSensitive(1);

    ❯❱ rules.mastg-android-accessibility-data-sensitive-disabled
          ❰❰ Blocking ❱❱
          [MASVS-PLATFORM-3] setAccessibilityDataSensitive is used to explicitly disable the accessibility
          data sensitivity of a view                                                                      

           82┆ confirmButton.setAccessibilityDataSensitive(2);
  • Line 64: the password field calls setAccessibilityDataSensitive(1).
  • Line 67: the one-time code field calls setFilterTouchesWhenObscured(true).
  • Line 71: the payment container calls setAccessibilityDataSensitive(1).
  • Line 82: the Confirm Payment button calls setAccessibilityDataSensitive(2).

Evaluation

The test case fails because two views that handle sensitive data aren't accessibility data sensitive:

  • The username field (line 61) doesn't appear in the output because the app doesn't configure any protection for it.
  • The Confirm Payment button (line 82) is reported by the mastg-android-accessibility-data-sensitive-disabled rule because the app calls setAccessibilityDataSensitive(2) on it, which overrides the protection inherited from the payment container.

The remaining views are protected:

  • The password field (line 64) is explicitly marked as accessibility data sensitive.
  • The one-time code field (line 67) sets filterTouchesWhenObscured and keeps the default ACCESSIBILITY_DATA_SENSITIVE_AUTO value, so it's treated as accessibility data sensitive.
  • The card number field (line 72) doesn't appear in the output, but the payment container (line 71) is marked as accessibility data sensitive and the field keeps the default value, so it inherits the protection.

Note that the output only lists the views for which the app configures the protection. Views without any configuration, such as the username field (line 61) and the Cancel button (line 85), don't appear, so you have to find them by reviewing the reverse-engineered code. This is manageable in a small sample but hard in a real app. Runtime Accessibility Data Sensitivity of Sensitive Views with Frida shows how enumerating the views at runtime lists every view on the screen, including these, together with its effective value.

When you tap Start, the app confirms these results at runtime by listing the value returned by isAccessibilityDataSensitive for each view: false for the username field and the Confirm Payment button, and true for the other fields.