Skip to content

MASTG-DEMO-0160: Runtime Accessibility Data Sensitivity of Sensitive Views with Frida

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

Sample

This demo uses the same sample as Sensitive Views Without Accessibility Data Sensitivity. The app creates a login and payment form with views that handle sensitive data, each using a different accessibility data sensitivity configuration:

  1. Username field: isn't marked as accessibility data sensitive.
  2. Password field: is explicitly marked as accessibility data sensitive.
  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).

MastgTest.kt
  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)
        }
    }
}

Steps

  1. Install the app on a device running Android 14 (API level 34) or higher ( Installing Apps).
  2. Make sure you have Frida (Android) installed on your machine and the frida-server running on the device.
  3. Run run.sh to spawn the app with Frida. The script uses Method Hooking to hook the relevant API calls.
  4. Tap the Start button.
  5. Use Inspecting the UI Hierarchy to obtain the view hierarchy of the screen. The script does this automatically shortly after the app changes the hooked settings. On other screens, call dumpViews() from the Frida REPL.
  6. In another terminal, use Taking Screenshots to take a screenshot of the screen with adb:

    adb exec-out screencap -p > screenshot.png
    
  7. Stop the script by pressing Ctrl+C and/or q to quit the Frida CLI.

1
2
3
4
#!/bin/bash

# Spawn the app with Frida, hook the accessibility data sensitivity setters, and dump the view hierarchy
frida -U -f org.owasp.mastestapp -l ./script.js -o 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
 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
// Hooks the View setters that configure accessibility data sensitivity and dumps the view hierarchy of the
// foreground activity with the effective isAccessibilityDataSensitive() value of each view.
// The dump runs automatically shortly after the app changes these settings. You can also call dumpViews()
// from the Frida REPL at any time, for example, after navigating to another screen that handles sensitive data.

const SENSITIVITY_MODES = { 0: "AUTO", 1: "YES", 2: "NO" };
const BACKTRACE_LINES = 6;
const DUMP_DELAY_MS = 1500;

let pendingDump = null;

function backtrace() {
    const Log = Java.use("android.util.Log");
    const Exception = Java.use("java.lang.Exception");
    const lines = Log.getStackTraceString(Exception.$new()).split("\n").slice(1, 1 + BACKTRACE_LINES);
    return lines.map(line => "    " + line.trim()).join("\n");
}

function describe(view) {
    const TextView = Java.use("android.widget.TextView");
    const EditText = Java.use("android.widget.EditText");
    let description = view.getClass().getName();

    const id = view.getId();
    if (id !== -1) {
        try {
            description += ` id=${view.getResources().getResourceEntryName(id)}`;
        } catch (e) {
            // The view uses a generated ID without a resource entry.
        }
    }

    if (TextView.class.isInstance(view)) {
        const textView = Java.cast(view, TextView);
        const hint = textView.getHint();
        if (hint !== null) {
            description += ` hint="${hint.toString()}"`;
        }
        // Don't print the content of input fields to avoid logging sensitive data.
        if (!EditText.class.isInstance(view)) {
            const text = textView.getText();
            if (text !== null && text.length() > 0) {
                description += ` text="${text.toString()}"`;
            }
        }
    }
    return description;
}

function walk(view, depth, lines) {
    const ViewGroup = Java.use("android.view.ViewGroup");
    lines.push(
        `${"  ".repeat(depth)}${describe(view)}` +
        ` isAccessibilityDataSensitive=${view.isAccessibilityDataSensitive()}` +
        ` filterTouchesWhenObscured=${view.getFilterTouchesWhenObscured()}`
    );
    if (ViewGroup.class.isInstance(view)) {
        const group = Java.cast(view, ViewGroup);
        for (let i = 0; i < group.getChildCount(); i++) {
            walk(group.getChildAt(i), depth + 1, lines);
        }
    }
}

function dumpViews() {
    Java.perform(() => {
        Java.scheduleOnMainThread(() => {
            Java.choose("android.app.Activity", {
                onMatch(activity) {
                    if (activity.isFinishing() || activity.isDestroyed() || !activity.hasWindowFocus()) {
                        return;
                    }
                    const lines = [];
                    walk(activity.getWindow().getDecorView(), 0, lines);
                    console.log(`\n[*] View hierarchy of ${activity.getClass().getName()}:`);
                    console.log(lines.join("\n"));
                },
                onComplete() {
                    console.log("\n[*] Finished dumping the view hierarchy.");
                }
            });
        });
    });
}

function scheduleDump() {
    if (pendingDump !== null) {
        clearTimeout(pendingDump);
    }
    pendingDump = setTimeout(() => {
        pendingDump = null;
        dumpViews();
    }, DUMP_DELAY_MS);
}

globalThis.dumpViews = dumpViews;

Java.perform(() => {
    const View = Java.use("android.view.View");

    if (View.setAccessibilityDataSensitive === undefined || View.isAccessibilityDataSensitive === undefined) {
        console.log("[-] Accessibility data sensitivity APIs aren't available. Use a device running Android 14 (API level 34) or higher.");
        return;
    }

    View.setAccessibilityDataSensitive.implementation = function (mode) {
        console.log(`\n[setAccessibilityDataSensitive] ${describe(this)} mode=${SENSITIVITY_MODES[mode] ?? mode}`);
        console.log(backtrace());
        this.setAccessibilityDataSensitive(mode);
        scheduleDump();
    };

    View.setFilterTouchesWhenObscured.implementation = function (enabled) {
        console.log(`\n[setFilterTouchesWhenObscured] ${describe(this)} enabled=${enabled}`);
        console.log(backtrace());
        this.setFilterTouchesWhenObscured(enabled);
        scheduleDump();
    };

    console.log("[*] Hooks installed. Tap Start, or call dumpViews() to dump the current screen.");
});

The Frida script covers both techniques:

  • Hooks ( Method Hooking): it hooks setAccessibilityDataSensitive and setFilterTouchesWhenObscured and prints the arguments and a backtrace for each call.
  • View hierarchy ( Inspecting the UI Hierarchy): its dumpViews() function enumerates the views of the foreground activity and prints the effective value returned by isAccessibilityDataSensitive for each view, which includes the protection inherited from parent views and implied by filterTouchesWhenObscured.

Observation

The output shows the calls to the hooked setters, including their arguments and backtraces, followed by the view hierarchy of the screen with the effective accessibility data sensitivity of each view.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[*] Hooks installed. Tap Start, or call dumpViews() to dump the current screen.

[setAccessibilityDataSensitive] android.widget.EditText hint="Password" mode=YES
    at android.view.View.setAccessibilityDataSensitive(Native Method)
    at org.owasp.mastestapp.MastgTest.mastgTest(MastgTest.kt:53)
    at org.owasp.mastestapp.MainActivityKt.MainScreen$lambda$4$0(MainActivity.kt:97)
    at org.owasp.mastestapp.MainActivityKt.$r8$lambda$R4Oi7w_P465QEr26at0FWIUKYxE(Unknown Source:0)
    at org.owasp.mastestapp.MainActivityKt$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
    at androidx.compose.foundation.AbstractClickableNode.performClick(Clickable.kt:1701)

[setFilterTouchesWhenObscured] android.widget.EditText hint="One-time code" enabled=true
    at android.view.View.setFilterTouchesWhenObscured(Native Method)
    at org.owasp.mastestapp.MastgTest.mastgTest(MastgTest.kt:58)
    at org.owasp.mastestapp.MainActivityKt.MainScreen$lambda$4$0(MainActivity.kt:97)
    at org.owasp.mastestapp.MainActivityKt.$r8$lambda$R4Oi7w_P465QEr26at0FWIUKYxE(Unknown Source:0)
    at org.owasp.mastestapp.MainActivityKt$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
    at androidx.compose.foundation.AbstractClickableNode.performClick(Clickable.kt:1701)

[setAccessibilityDataSensitive] android.widget.LinearLayout mode=YES
    at android.view.View.setAccessibilityDataSensitive(Native Method)
    at org.owasp.mastestapp.MastgTest.mastgTest(MastgTest.kt:65)
    at org.owasp.mastestapp.MainActivityKt.MainScreen$lambda$4$0(MainActivity.kt:97)
    at org.owasp.mastestapp.MainActivityKt.$r8$lambda$R4Oi7w_P465QEr26at0FWIUKYxE(Unknown Source:0)
    at org.owasp.mastestapp.MainActivityKt$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
    at androidx.compose.foundation.AbstractClickableNode.performClick(Clickable.kt:1701)

[setAccessibilityDataSensitive] android.widget.Button text="Confirm Payment" mode=NO
    at android.view.View.setAccessibilityDataSensitive(Native Method)
    at org.owasp.mastestapp.MastgTest.mastgTest(MastgTest.kt:75)
    at org.owasp.mastestapp.MainActivityKt.MainScreen$lambda$4$0(MainActivity.kt:97)
    at org.owasp.mastestapp.MainActivityKt.$r8$lambda$R4Oi7w_P465QEr26at0FWIUKYxE(Unknown Source:0)
    at org.owasp.mastestapp.MainActivityKt$$ExternalSyntheticLambda0.invoke(D8$$SyntheticClass:0)
    at androidx.compose.foundation.AbstractClickableNode.performClick(Clickable.kt:1701)

[*] View hierarchy of org.owasp.mastestapp.MainActivity:
com.android.internal.policy.DecorView isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
  android.widget.LinearLayout isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
    android.view.ViewStub id=action_mode_bar_stub isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
    android.widget.FrameLayout id=content isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
      androidx.compose.ui.platform.ComposeView isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
        androidx.compose.ui.platform.AndroidComposeView isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
          androidx.compose.material.ripple.RippleContainer isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
            androidx.compose.material.ripple.RippleHostView isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
      android.widget.LinearLayout isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
        android.widget.EditText hint="Username" isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
        android.widget.EditText hint="Password" isAccessibilityDataSensitive=true filterTouchesWhenObscured=false
        android.widget.EditText hint="One-time code" isAccessibilityDataSensitive=true filterTouchesWhenObscured=true
        android.widget.LinearLayout isAccessibilityDataSensitive=true filterTouchesWhenObscured=false
          android.widget.EditText hint="Card number" isAccessibilityDataSensitive=true filterTouchesWhenObscured=false
          android.widget.Button text="Confirm Payment" isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
        android.widget.Button text="Cancel" isAccessibilityDataSensitive=false filterTouchesWhenObscured=false
  androidx.activity.EdgeToEdge$enableEdgeToEdge$1$2 isAccessibilityDataSensitive=false filterTouchesWhenObscured=false

[*] Finished dumping the view hierarchy.
  • The hooks capture four calls from MastgTest.mastgTest: setAccessibilityDataSensitive with the YES mode on the Password field (MastgTest.kt:53) and on the payment container, a LinearLayout (MastgTest.kt:65), setFilterTouchesWhenObscured(true) on the One-time code field (MastgTest.kt:58), and setAccessibilityDataSensitive with the NO mode on the Confirm Payment button (MastgTest.kt:75).
  • The view hierarchy shows the form at the end of the content frame. The Username field and the Confirm Payment button return isAccessibilityDataSensitive=false, while the Password, One-time code, and Card number fields return true.

The screenshot shows the screen with the form at the bottom:

It also shows which views display or accept sensitive data: the Username, Password, One-time code, and Card number fields, and the Confirm Payment button. The Cancel button doesn't handle sensitive data.

Evaluation

The test case fails because two views that handle sensitive data return false from isAccessibilityDataSensitive:

  • The Username field doesn't call any of the hooked setters, and the view hierarchy confirms it isn't protected.
  • The Confirm Payment button explicitly disables the protection with setAccessibilityDataSensitive and the NO mode, as shown in the hook output and its backtrace (MastgTest.kt:75), even though the payment container is marked as accessibility data sensitive.

The Password, One-time code, and Card number fields return true. The card number field doesn't call any of the hooked setters, but the view hierarchy shows that it inherits the protection from the payment container. Only the enumeration of the view hierarchy reveals this inherited protection, and the unprotected username field, because neither involves a call to the hooked setters.

android.widget.LinearLayout isAccessibilityDataSensitive=true filterTouchesWhenObscured=false
    android.widget.EditText hint="Card number" isAccessibilityDataSensitive=true filterTouchesWhenObscured=false
    android.widget.Button text="Confirm Payment" isAccessibilityDataSensitive=false filterTouchesWhenObscured=false

The Cancel button also returns false, which is expected because it doesn't handle sensitive data.