|
1 | 1 | package org.owasp.mastestapp; |
2 | 2 |
|
3 | | -import android.os.Bundle; |
| 3 | +import android.content.Context; |
4 | 4 | import android.view.MotionEvent; |
5 | 5 | import android.widget.Button; |
6 | | -import android.widget.Toast; |
7 | | -import androidx.activity.ComponentActivity; |
8 | | -import androidx.compose.foundation.layout.ColumnKt; |
9 | | -import androidx.compose.foundation.layout.PaddingKt; |
10 | | -import androidx.compose.material3.ButtonKt; |
11 | | -import androidx.compose.material3.TextKt; |
12 | | -import androidx.compose.runtime.Composer; |
13 | | -import androidx.compose.ui.Modifier; |
14 | | -import androidx.compose.ui.unit.Dp; |
15 | | -import androidx.compose.ui.viewinterop.AndroidViewKt; |
16 | | -import kotlin.jvm.functions.Function0; |
17 | | -import kotlin.jvm.functions.Function1; |
18 | | -import kotlin.jvm.functions.Function2; |
19 | | -import kotlin.jvm.internal.Lambda; |
| 6 | +import android.widget.LinearLayout; |
| 7 | +import kotlin.jvm.internal.Intrinsics; |
20 | 8 |
|
21 | | -public final class MainActivity extends ComponentActivity { |
22 | | - public void onCreate(Bundle savedInstanceState) { |
23 | | - super.onCreate(savedInstanceState); |
24 | | - this.enableEdgeToEdge(); |
25 | | - this.setContent(new Lambda(0) { |
26 | | - public final void invoke(Composer $composer, int $changed) { |
27 | | - MainScreenKt.MainScreen($composer, 0); |
28 | | - } |
29 | | - }); |
| 9 | +public final class MastgTest { |
| 10 | + private final Context context; |
| 11 | + |
| 12 | + public MastgTest(Context context) { |
| 13 | + Intrinsics.checkNotNullParameter(context, "context"); |
| 14 | + this.context = context; |
30 | 15 | } |
31 | | -} |
32 | 16 |
|
33 | | -public final class MainScreenKt { |
34 | | - public static final void MainScreen(Composer $composer, int $changed) { |
35 | | - Composer $composer2 = $composer.startRestartGroup(0); |
36 | | - if ($changed == 0) { |
37 | | - if (!$composer2.getSkipping()) { |
38 | | - ColumnKt.m586Column(PaddingKt.m565padding(Modifier.Companion, Dp.m5307constructorimpl(16)), null, null, new Lambda(3) { |
39 | | - public final void invoke(ColumnScope $this$Column, Composer $composer, int $changed) { |
40 | | - Composer $composer2 = $composer; |
41 | | - ColumnScope columnScope = $this$Column; |
42 | | - |
43 | | - // FAIL: [MASTG-TEST-0035] Vulnerable button without overlay protection |
44 | | - ButtonKt.m1334Button(new Lambda(0) { |
45 | | - public final void invoke() { |
46 | | - // Sensitive action: confirming a payment |
47 | | - } |
48 | | - }, PaddingKt.m565padding(Modifier.Companion.fillMaxWidth(), Dp.m5307constructorimpl(8)), false, null, null, null, null, null, new Lambda(3) { |
49 | | - public final void invoke(RowScope $this$Button, Composer $composer, int $changed) { |
50 | | - TextKt.m3574Text("Vulnerable: Confirm Payment", null, 0L, 0L, null, null, null, 0L, null, null, 0L, 0, false, 0, null, null, $composer, 0, 0, 131070); |
51 | | - } |
52 | | - }, $composer2, 805306368, 508); |
53 | | - |
54 | | - // PASS: [MASTG-TEST-0035] Button with overlay protection |
55 | | - AndroidViewKt.m4555AndroidView(new Lambda(1) { |
56 | | - public final Button invoke(Context context) { |
57 | | - Button button = new Button(context); |
58 | | - button.setText("Protected: Confirm Payment"); |
59 | | - button.setFilterTouchesWhenObscured(true); |
60 | | - button.setOnClickListener(new View.OnClickListener() { |
61 | | - public void onClick(View view) { |
62 | | - Toast.makeText(context, "Payment confirmed", 0).show(); |
63 | | - } |
64 | | - }); |
65 | | - return button; |
66 | | - } |
67 | | - }, PaddingKt.m565padding(Modifier.Companion.fillMaxWidth(), Dp.m5307constructorimpl(8)), null, null, $composer2, 3080, 12); |
68 | | - |
69 | | - // PASS: [MASTG-TEST-0035] Custom view with manual obscured check |
70 | | - AndroidViewKt.m4555AndroidView(new Lambda(1) { |
71 | | - public final Button invoke(Context context) { |
72 | | - return new Button(context) { |
73 | | - public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
74 | | - if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
75 | | - Toast.makeText(this.getContext(), "Touch blocked - window obscured", 0).show(); |
76 | | - return false; |
77 | | - } |
78 | | - return super.onFilterTouchEventForSecurity(event); |
79 | | - } |
80 | | - |
81 | | - { |
82 | | - this.setText("Custom Protection: Grant Permission"); |
83 | | - this.setOnClickListener(new View.OnClickListener() { |
84 | | - public void onClick(View view) { |
85 | | - Toast.makeText(Button.this.getContext(), "Permission granted", 0).show(); |
86 | | - } |
87 | | - }); |
88 | | - } |
89 | | - }; |
90 | | - } |
91 | | - }, PaddingKt.m565padding(Modifier.Companion.fillMaxWidth(), Dp.m5307constructorimpl(8)), null, null, $composer2, 3080, 12); |
92 | | - } |
93 | | - }, $composer2, 438, 6); |
| 17 | + public final String mastgTest() { |
| 18 | + LinearLayout layout = new LinearLayout(this.context); |
| 19 | + layout.setOrientation(1); |
| 20 | + |
| 21 | + // FAIL: [MASTG-TEST-0x35] Sensitive button without overlay protection |
| 22 | + Button vulnerableButton = new Button(this.context); |
| 23 | + vulnerableButton.setText("Vulnerable: Confirm Payment"); |
| 24 | + vulnerableButton.setOnClickListener(view -> { |
| 25 | + // Sensitive action: confirming a payment |
| 26 | + }); |
| 27 | + layout.addView(vulnerableButton); |
| 28 | + |
| 29 | + // PASS: [MASTG-TEST-0x35] Button with overlay protection using filterTouchesWhenObscured |
| 30 | + Button protectedButton = new Button(this.context); |
| 31 | + protectedButton.setText("Protected: Confirm Payment"); |
| 32 | + protectedButton.setFilterTouchesWhenObscured(true); |
| 33 | + protectedButton.setOnClickListener(view -> { |
| 34 | + // Sensitive action protected from overlay attacks |
| 35 | + }); |
| 36 | + layout.addView(protectedButton); |
| 37 | + |
| 38 | + // PASS: [MASTG-TEST-0x35] Custom view with manual obscured check |
| 39 | + Button customProtectedButton = new Button(this.context) { |
| 40 | + public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
| 41 | + if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 42 | + // Window is obscured, filter the touch event |
| 43 | + return false; |
| 44 | + } |
| 45 | + return super.onFilterTouchEventForSecurity(event); |
94 | 46 | } |
95 | | - } |
| 47 | + }; |
| 48 | + customProtectedButton.setText("Custom Protection: Grant Permission"); |
| 49 | + customProtectedButton.setOnClickListener(view -> { |
| 50 | + // Sensitive permission grant protected by custom implementation |
| 51 | + }); |
| 52 | + layout.addView(customProtectedButton); |
| 53 | + |
| 54 | + return "Created buttons with various overlay protections:\n" + |
| 55 | + "1. Vulnerable button (no protection)\n" + |
| 56 | + "2. Protected button (filterTouchesWhenObscured)\n" + |
| 57 | + "3. Custom protected button (onFilterTouchEventForSecurity)"; |
96 | 58 | } |
97 | 59 | } |
0 commit comments