feat: add address poisoning detection to PhishingController#8171
feat: add address poisoning detection to PhishingController#8171AugmentedMode wants to merge 7 commits intomainfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| this.#transactionRecipients.add(address); | ||
| } | ||
| this.#rebuildKnownRecipients(); | ||
| } |
There was a problem hiding this comment.
Premature clear causes recipient data loss on error
Medium Severity
#setKnownRecipientsFromTransactionState calls this.#transactionRecipients.clear() before iterating state.transactions. If #getConfirmedTransactionRecipients throws (e.g. state.transactions is undefined), the set is left empty and #rebuildKnownRecipients is never called. This leaves #transactionRecipients empty while #knownRecipients retains stale entries. On the next successful #rebuildKnownRecipients call (triggered by an address book update), those stale transaction recipients are permanently lost. The same pattern exists in #setKnownRecipientsFromAddressBookState.
Additional Locations (1)
|
|
||
| #onAddressBookControllerStateChange(state: AddressBookControllerState): void { | ||
| this.#setKnownRecipientsFromAddressBookState(state); | ||
| } |
There was a problem hiding this comment.
Address book handler lacks error handling unlike transaction handler
Medium Severity
#onAddressBookControllerStateChange directly calls #setKnownRecipientsFromAddressBookState without a try-catch, unlike #onTransactionControllerStateChange which wraps its recipient update in a nested try-catch. If the address book state is malformed, the unhandled error propagates into the messenger's event dispatch, potentially disrupting other event listeners or causing an unhandled exception.


Explanation
This PR adds address poisoning detection to
@metamask/phishing-controllerby:findSimilarAddressesutility that compares a candidate address against known recipients using prefix/suffix matching heuristicsPhishingController:checkAddressPoisoningmessenger action that clients can call to check if a recipient address looks like a poisoning attemptTransactionControllerstateAddressBookControllerstateReferences
Checklist
Note
Medium Risk
Adds new cross-controller subscriptions and state hydration paths (transactions + address book), which can affect runtime behavior and messaging contracts if states/events differ across environments.
Overview
Adds address-poisoning detection to
PhishingControllervia a newfindSimilarAddressesutility andPhishingController:checkAddressPoisoningaction that returns similarity metadata (prefix/suffix match lengths, score, diff indices).The controller now hydrates and maintains a set of known recipient addresses from confirmed
TransactionControllerrecipients andAddressBookControllerentries, subscribing to both controllers’stateChangeevents to keep this set updated; errors updating known recipients are logged but do not block existing token scanning. This introduces new exported types (SimilarAddressMatch,SimilarityOptions), adds@metamask/address-book-controlleras a dependency, and expands tests accordingly.Written by Cursor Bugbot for commit e2235a7. This will update automatically on new commits. Configure here.