-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
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. |
Builds ready [46f8e6b]
Page Load Metrics (1360 ± 140 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Changes look good to me, it will be nice to have a review by @brad-decker also. |
app/scripts/lib/message-manager.js
Outdated
action: 'Sign Request Reject', | ||
type: msg.type, | ||
ui_customizations: | ||
msg.securityProviderResponse?.flagAsDangerous === 1 | ||
? ['flagged_as_malicious'] | ||
: [], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
A request from data team: we should use |
Also, can you plz ensure that appropriate tests are added for these code changes.
ee6f999
to
351db3f
Compare
Builds ready [1e28710]
Page Load Metrics (1507 ± 47 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Some issues from QA:
provider-method-event.mp4
provider-signatures.mp4 |
const from = req?.params?.[1]; | ||
const paramsExamplePassword = req?.params?.[2]; | ||
|
||
const { isSIWEMessage } = detectSIWE({ data }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Builds ready [cc55ac7]
Page Load Metrics (1636 ± 42 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [d83b223]
Page Load Metrics (1520 ± 29 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
d83b223
to
cbd0e22
Compare
Builds ready [cbd0e22]
Page Load Metrics (1707 ± 62 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this 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'] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds okay to me
} catch (e) { | ||
console.warn( | ||
`createRPCMethodTrackingMiddleware: Error calling securityProviderRequest - ${e}`, | ||
); |
There was a problem hiding this comment.
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
to not block dapp rpc requests
49a2da2
to
e70fb73
Compare
Builds ready [e70fb73]
Page Load Metrics (1495 ± 33 ms)
|
Builds ready [8b3d3cf]
Page Load Metrics (2260 ± 62 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
const paramsExamplePassword = req?.params?.[2]; | ||
|
||
msgParams = { | ||
...paramsExamplePassword, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 valueopensea
if the user has enabled theOpenSea
security provider feature underSettings > Experimental
.If the user turns off the security provider under
Settings > Experimental
, then the user profile propertysecurity_provider
is updated and theopensea
value removed from it.Additionally there is a new property called
ui_customizations
added toTransaction Approved
,Transaction Rejected
,Signature Approved
andSignature Rejected
events.This property receives one of the following values:
['flagged_as_malicious']
when the transaction was flagged as malicious['flagged_as_safety_unknown']
when the transaction was flagged as safety unknownnull
in all other casesby 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:
OpenSea
security provider underSettings > Experimental
SEND LEGACY TRANSACTION
SEND EIP 1559 TRANSACTION
ETH SIGN
PERSONAL SIGN
SIGN TYPED DATA
SIGN TYPED DATA V3
SIGN TYPED DATA V4