Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSea security provider metrics #17688

Merged
merged 24 commits into from
Mar 23, 2023
Merged

Conversation

filipsekulic
Copy link
Contributor

@filipsekulic filipsekulic commented Feb 9, 2023

Explanation

Added metrics for the OpenSea security provider.

Created a new user profile property called security_provider. This property is a type list and receives the value opensea if the user has enabled the OpenSea security provider feature under Settings > Experimental.
If the user turns off the security provider under Settings > Experimental, then the user profile property security_provider is updated and the opensea value removed from it.

Additionally there is a new property called ui_customizations added to Transaction Approved, Transaction Rejected, Signature Approved and Signature Rejected events.
This property receives one of the following values:

  1. ['flagged_as_malicious'] when the transaction was flagged as malicious
  2. ['flagged_as_safety_unknown'] when the transaction was flagged as safety unknown
  3. null in all other cases

by the transaction security provider.

Manual testing steps

In the .metamaskrc set the transaction security feature flag to 1 - TRANSACTION_SECURITY_PROVIDER=1.

Follow the procedure for testing the metrics event and check the response in the background console of the extension - background.html.

Cases to check:

  • enable/disable the OpenSea security provider under Settings > Experimental
  • SEND LEGACY TRANSACTION
  • SEND EIP 1559 TRANSACTION
  • ETH SIGN
  • PERSONAL SIGN
  • SIGN TYPED DATA
  • SIGN TYPED DATA V3
  • SIGN TYPED DATA V4

@filipsekulic filipsekulic self-assigned this Feb 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2023

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot
Copy link
Collaborator

Builds ready [46f8e6b]
Page Load Metrics (1360 ± 140 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint93141112126
domContentLoaded95917981321291140
load95918271360292140
domInteractive95917981321291140
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1549 bytes
  • ui: 0 bytes
  • common: 38 bytes

@filipsekulic filipsekulic marked this pull request as ready for review February 14, 2023 15:14
@filipsekulic filipsekulic requested a review from a team as a code owner February 14, 2023 15:14
@jpuri
Copy link
Contributor

jpuri commented Feb 14, 2023

Changes look good to me, it will be nice to have a review by @brad-decker also.

jpuri
jpuri previously approved these changes Feb 14, 2023
Comment on lines 249 to 254
action: 'Sign Request Reject',
type: msg.type,
ui_customizations:
msg.securityProviderResponse?.flagAsDangerous === 1
? ['flagged_as_malicious']
: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the ui_customization should be added to the events in createRPCMethodTrackingMiddleware versus adding a new event and renaming events here and in the other message managers.

Copy link
Contributor Author

@filipsekulic filipsekulic Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @brad-decker,
Do you have a suggestion how it should look like? I mean, in the middleware you mentioned I need the information I get from the message - msg.securityProviderResponse?.flagAsDangerous.
Also, I have to mention the presence of the property that shares the same name as the one mentioned above - https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/createRPCMethodTrackingMiddleware.js#L173.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would add your value to the array already present. The events in these confirmations are not the ones we rely upon. Let me dig in a bit and see how you can get access to the value you need

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipsekulic it looks to me you can pass securityProviderRequest to the createRPCMethodTrackingMiddleware instantiation in metamask controller. You will have access to data and method type on the request and can call the securityProviderRequest. Now its a little wasteful, but we don't add our internal id to the response of signatures so we can't retrieve it from this level we'll have to call it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker I tried it, but without success. The reason is that the data being passed to the securityProviderRequest from createRPCMethodTrackingMiddleware (req) is not proper, so as the response in that case. The proper data being sent is shown in the attached image (personal-message-manager.js).

Data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipsekulic look at the detectSIWE implementation. Its done in both places as well. You will need to formulate the data object that securityProviderCheck needs -- note that in perosnal-message-manager that includes the 'id' of the transaction but the id key isn't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker I implemented the solution you suggested. Thanks! However, I could not fix the failing test - createRPCMethodTrackingMiddleware.test.js. I must be missing something. Hope you can help me. I would appreciate your help!

@bschorchit
Copy link

A request from data team: we should use security_providers (plural) instead of security_provider (singular) for the name of the user profile property. Could you make this small change, @filipsekulic ? Thank you!

@jpuri jpuri dismissed their stale review February 15, 2023 05:36

Also, can you plz ensure that appropriate tests are added for these code changes.

@filipsekulic filipsekulic force-pushed the open-sea-security-provider-metrics branch 2 times, most recently from ee6f999 to 351db3f Compare March 1, 2023 14:16
@metamaskbot
Copy link
Collaborator

Builds ready [1e28710]
Page Load Metrics (1507 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint154208177178
domContentLoaded1315156114436129
load1315166415079847
domInteractive1315156114436129
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1405 bytes
  • ui: 0 bytes
  • common: 40 bytes

@seaona
Copy link
Contributor

seaona commented Mar 2, 2023

Some issues from QA:

  • When I load MM for the first time, I can see a background console error related to detectSIWE , saying TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined

image

  • Sometimes the event for Send/Send Legacy is not emitted.
provider-method-event.mp4
  • I haven't observed any metrics event related to the provider, when interacting with Signatures (any kind of signature)
provider-signatures.mp4

app/scripts/lib/personal-message-manager.js Outdated Show resolved Hide resolved
app/scripts/lib/message-manager.js Outdated Show resolved Hide resolved
app/scripts/lib/typed-message-manager.js Outdated Show resolved Hide resolved
app/scripts/lib/createRPCMethodTrackingMiddleware.js Outdated Show resolved Hide resolved
const from = req?.params?.[1];
const paramsExamplePassword = req?.params?.[2];

const { isSIWEMessage } = detectSIWE({ data });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this call here, it should only work with personal-sign. Why do we need the isSIWEMessage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought it's not just for the personal-sign. I'll fix it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brad-decker
You were right, there is no need for the isSIWEMessage... I don't know why I put it, thought it might was mandatory for all signatures, because at that moment I was looking into the request data being sent for the personal-sign. Suppose that was the case.
Thanks once again! Hope it's okay now.

@metamaskbot
Copy link
Collaborator

Builds ready [cc55ac7]
Page Load Metrics (1636 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint104160118136
domContentLoaded1448174215947436
load1448176616368742
domInteractive1448174215947436
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1026 bytes
  • ui: 0 bytes
  • common: 40 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [d83b223]
Page Load Metrics (1520 ± 29 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint95145117147
domContentLoaded1412161915055627
load1412170215206129
domInteractive1412161915055627
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 970 bytes
  • ui: 0 bytes
  • common: 40 bytes

brad-decker
brad-decker previously approved these changes Mar 2, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [cbd0e22]
Page Load Metrics (1707 ± 62 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint100165122178
domContentLoaded14961978166712661
load15071978170712962
domInteractive14961978166712661
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 970 bytes
  • ui: 0 bytes
  • common: 40 bytes

jpuri
jpuri previously approved these changes Mar 3, 2023
Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@digiwand digiwand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the fetch request from securityProviderCheck somehow fails, it will stop the dapp request. We will need to handle the error here


properties.ui_customizations =
securityProviderResponse?.flagAsDangerous === 1
? ['flagged_as_malicious']
Copy link
Contributor

@digiwand digiwand Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add this to METAMETRICS_KEY_OPTIONS in constants/metametrics.js. We could update this here or I can update this in a follow-up PR: #18008

Copy link
Contributor Author

@filipsekulic filipsekulic Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds okay to me

app/scripts/lib/createRPCMethodTrackingMiddleware.js Outdated Show resolved Hide resolved
} catch (e) {
console.warn(
`createRPCMethodTrackingMiddleware: Error calling securityProviderRequest - ${e}`,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

choosing console.warn here since we already log the error in securityProviderRequest (metamask-controller.js). maybe there are better ways to go about this. happy to hear other suggestions

@filipsekulic filipsekulic force-pushed the open-sea-security-provider-metrics branch from 49a2da2 to e70fb73 Compare March 22, 2023 08:19
@metamaskbot
Copy link
Collaborator

Builds ready [e70fb73]
Page Load Metrics (1495 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint90153113147
domContentLoaded1370163114856632
load1393164714957033
domInteractive1370163114856632

@metamaskbot
Copy link
Collaborator

Builds ready [8b3d3cf]
Page Load Metrics (2260 ± 62 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint141213162178
domContentLoaded19522390224511957
load19732465226013062
domInteractive19522390224511957
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2004 bytes
  • ui: 0 bytes
  • common: 40 bytes

@filipsekulic filipsekulic requested a review from digiwand March 23, 2023 11:39
@bschorchit bschorchit merged commit 0351309 into develop Mar 23, 2023
@bschorchit bschorchit deleted the open-sea-security-provider-metrics branch March 23, 2023 17:01
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2023
const paramsExamplePassword = req?.params?.[2];

msgParams = {
...paramsExamplePassword,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upon a second look today, I realized this is an issue. It can splay a string. Not sure how we missed this the first time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working with another engineer to apply a fix for this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants