Repository navigation
fix: only dismiss an alert that is on screen - #72
Draft
cryptotavares wants to merge 1 commit into
Draft
cryptotavares wants to merge 1 commit into
cryptotavares wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the mm CLI v2 effort (audit item N1).
Problem
dismissAlert(accept)searched the whole screen for each label inACCEPT_LABELS/DENY_LABELS. It used the fuzzy match (case-insensitive substring), then tapped the frame centre with no hit-test. With no alert on screen, it tapped an unrelated control.mm dismiss-alertexposes this on devices that hold real funds.The old code, run on a live Android Settings home snapshot with no alert on screen:
OKmatches "Tokens" the same way, andContinueorConfirmmatches any such button in the app.Solution
flowchart TD A["dismissAlert(accept)"] --> B[snapshot] B --> C{"Alert on screen?<br/>iOS: type Alert<br/>Android: window with an alert id"} C -->|no| X["Error: No alert on screen. Nothing is tapped."] C -->|yes| D{"Button inside the alert<br/>with an exact label?"} D -->|no| Y["Error: No alert button found in the alert. Nothing is tapped."] D -->|yes| E["tapElement(button): hit-test"] E -->|covered| Z["TargetObscuredError. Nothing is tapped."] E -->|clear| F[tap] classDef new fill:#fff3cd,stroke:#d39e00 classDef stop fill:#f8d7da,stroke:#c82333 class C,D,E new class X,Y,Z stopYellow boxes are new. Red boxes stop the tap.
Supported alert shapes:
Alert, as idb reports it. This covers in-appUIAlertControlleralerts. SpringBoard alerts (for example "Open in MetaMask?") work only if idb reports them asAlertin the tree. This is not verified live.<package>:id/alertTitle,android:id/button1/2/3, or anycom.android.permissioncontroller/com.google.android.permissioncontrolleridThe label lists and their order are unchanged. A label matches when it equals the element's label or text, ignoring case.
What changes
No alert on screen; nothing was tapped.accepttaps the screen's "Allow" (earlier in the list)accepttaps the alert's OK;denytaps its CancelNo alert button found in the alert; nothing was tapped. Tried: …TargetObscuredError(TARGET_OBSCURED)The signature is unchanged. Failures still throw
Error; the obscured case throws the existingTargetObscuredError.Decisions for reviewers
ALLOWandDENY, so real buttons vary in case. Equality still rejects "Tokens" forOK.FrameLayout. The class never containsDialog. The ids are stable framework ids.tapElementwith the resolved elementdescribe-pointon iOS, the occlusion check on Android) and the same viewport check.getAlertTextas isReview guide
src/utils/alert-labels.tsfindAlertButton: exact match, list order kept, search only inside the alertsrc/backends/idb-backend.tsdismissAlert:findElement(…, { type: 'Alert', exact: true }), thentapElementsrc/backends/adb-backend.tsALERT_MARKER_ID,findAndroidAlert,dismissAlert*.test.tsdismissAlertblock per backend; the rows match the table aboveTesting
yarn build,yarn lintandyarn testpass (38 files, 1002 tests, 6 skipped). Coverage stays above the floors.dismissAlert, 5 of 6 tests fail on each backend. The deny-with-alert test passes on old code too, because the alert's Cancel happened to be the first fuzzy match.instrumentsnapshots):dismissAlert(true),dismissAlert(false)No alert on screen; nothing was tapped.The focused activity and the screen texts are the same before and after.alertTitle,button1OK,button2Cancel)dismissAlert(false)dismissAlert(true)dismissAlert(false)taps its Cancel. The device name is unchanged.Alertshape that idb reports.