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

Security Provider cleanup #19694

Merged
merged 6 commits into from
Jun 23, 2023
Merged

Security Provider cleanup #19694

merged 6 commits into from
Jun 23, 2023

Conversation

digiwand
Copy link
Contributor

@digiwand digiwand commented Jun 20, 2023

Explanation

no logic updates. just refactoring the OpenSea security provider logic.

The OpenSea security provider is planned to be deprecated and replaced. Cleaning the code a little will help us implement the new security provider and potentially help us maintain both as we transition.

  • Created a util function to abstract conditional logic - isSuspiciousSecurityProviderResponse
  • Moved SECURITY_PROVIDER_MESSAGE_SEVERITIES constant to a new shared/constants file
    • previously, the constant lived in a component folder. The problem was it was used outside of the component.
  • Renamed SECURITY_PROVIDER_MESSAGE_SEVERITIES -> SECURITY_PROVIDER_MESSAGE_SEVERITY
  • The conditional with a little difficult for me to understand. I updated the code to hopefully be a bit more understandable.
  • Add test for new util function

Affected Components:

  • Confirm Pages
  • Confirm Approve
  • Signature Requests
  • Signature Request Original
  • Signature Request SIWE
  • Token Allowance

--
Fixes: #19741
Relates to: /~https://github.com/MetaMask/MetaMask-planning/issues/558
Relates to: #17662

Screenshots/Screencaps

Before

After

Manual Testing Steps

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Contributor

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.

@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #19694 (511c077) into develop (4ae483c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #19694      +/-   ##
===========================================
- Coverage    70.79%   70.79%   -0.00%     
===========================================
  Files          988      989       +1     
  Lines        38366    38350      -16     
  Branches     10042    10022      -20     
===========================================
- Hits         27161    27149      -12     
+ Misses       11205    11201       -4     
Impacted Files Coverage Δ
...banner-message/security-provider-banner-message.js 100.00% <ø> (ø)
shared/constants/security-provider.ts 100.00% <100.00%> (ø)
shared/modules/security-provider.utils.ts 100.00% <100.00%> (ø)
...ontent/confirm-page-container-content.component.js 91.84% <100.00%> (-0.62%) ⬇️
...t-original/signature-request-original.component.js 61.11% <100.00%> (-1.65%) ⬇️
...p/signature-request-siwe/signature-request-siwe.js 71.93% <100.00%> (+1.93%) ⬆️
...p/signature-request/signature-request.component.js 76.71% <100.00%> (-1.21%) ⬇️
...prove-content/confirm-approve-content.component.js 77.65% <100.00%> (+0.06%) ⬆️
ui/pages/token-allowance/token-allowance.js 65.00% <100.00%> (-0.28%) ⬇️

@metamaskbot
Copy link
Collaborator

Builds ready [b5143b4]
Page Load Metrics (1924 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1192331572512
domContentLoaded15802270189218991
load165623001924212102
domInteractive15792270189218991
Bundle size diffs
  • background: 0 bytes
  • ui: -1828 bytes
  • common: 0 bytes

digiwand added 4 commits June 21, 2023 20:43
- util fn returns true if response is not verified and flagged
and support undefined param
- no logic changes
@digiwand digiwand marked this pull request as ready for review June 21, 2023 19:08
@digiwand digiwand requested a review from a team as a code owner June 21, 2023 19:08
@digiwand digiwand requested a review from FrederikBolding June 21, 2023 19:08
@digiwand digiwand added the team-confirmations-secure-ux-PR PRs from the confirmations team label Jun 21, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [511c077]
Page Load Metrics (1651 ± 57 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1052121362813
domContentLoaded14411934162412158
load15081949165111857
domInteractive14411934162412158
Bundle size diffs
  • background: 0 bytes
  • ui: -1926 bytes
  • common: 0 bytes

SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_MALICIOUS) ||
(txData?.securityProviderResponse &&
Object.keys(txData.securityProviderResponse).length === 0) ? (
{isSuspiciousResponse(txData?.securityProviderResponse) && (
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌🏿

Copy link
Contributor

@blackdevelopa blackdevelopa left a comment

Choose a reason for hiding this comment

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

Looks good to me

<SecurityProviderBannerMessage
securityProviderResponse={txData.securityProviderResponse}
/>
) : null}
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another approach could be moving this condition isSuspiciousResponse(txData?.securityProviderResponse) inside SecurityProviderBannerMessage component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this suggestion. We can apply it to the new security provider code

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.

Nice cleanup 👍

@digiwand digiwand merged commit 34375a5 into develop Jun 23, 2023
@digiwand digiwand deleted the security-provider-cleanup branch June 23, 2023 18:08
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
@metamaskbot metamaskbot added the release-10.34.0 Issue or pull request that will be included in release 10.34.0 label Jun 23, 2023
@digiwand digiwand linked an issue Jun 23, 2023 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-10.34.0 Issue or pull request that will be included in release 10.34.0 team-confirmations-secure-ux-PR PRs from the confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean OpenSea Security Provider Logic
4 participants