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

feat: support security alerts API #25544

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

vinistevam
Copy link
Contributor

@vinistevam vinistevam commented Jun 27, 2024

Description

This PR enables the use of the Security Alerts API to validate dApp requests, with a fallback to local PPOM validation if the API request fails.

Environment Variables

Add the following variables to .metamaskrc:

SECURITY_ALERTS_API_URL='http://localhost:3000'
SECURITY_ALERTS_API_ENABLED='true'

Additional Changes

Introduces the security_alert_source property to transaction and signature events, indicating api or local as the source.

Related Repository

Refer to the Security Alerts API repository for more details.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2514 https://github.com/MetaMask/MetaMask-planning/issues/2515

Manual testing steps

  1. Test blockaid regression

  2. add the envs

SECURITY_ALERTS_API_URL='https://security-alerts.dev-api.cx.metamask.io'
SECURITY_ALERTS_API_ENABLED='true'
  • Go to test dapp and trigger on of the malicious signatures
  • To verify in chrome go to dev tools > network. Search for security-alerts and find the call to the API service.

Existing PPOM logic should function as before, even with the above environment variables added, due to the fallback to the controller in the event of an error.

Screenshots/Recordings

image

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@vinistevam vinistevam added the team-confirmations Push issues to confirmations team label Jun 27, 2024
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.

Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.70%. Comparing base (d403213) to head (0fbd0e9).
Report is 9 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25544      +/-   ##
===========================================
+ Coverage    69.69%   69.70%   +0.02%     
===========================================
  Files         1350     1351       +1     
  Lines        47865    47890      +25     
  Branches     13199    13203       +4     
===========================================
+ Hits         33355    33380      +25     
  Misses       14510    14510              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [0fbd0e9]
Page Load Metrics (140 ± 174 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7311693126
domContentLoaded9321352
load431720140363174
domInteractive9321352
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.62 KiB (0.05%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@vinistevam vinistevam marked this pull request as ready for review June 28, 2024 06:05
@vinistevam vinistevam requested review from a team as code owners June 28, 2024 06:05
...ppomResponse,
securityAlertId,
};
} catch (error: unknown) {
return handlePPOMError(error, 'Error validateRequestWithPPOM#usePPOM: ');
Copy link
Member

Choose a reason for hiding this comment

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

Should we change the message here for clarity, or add separate try catch blocks in each validate method?

@@ -260,6 +260,10 @@ env:
- TEST_GAS_FEE_FLOWS: false
# Determines if feature flagged network ui new design
- ENABLE_NETWORK_UI_REDESIGN: ''
# Determines if uses the security alerts API to validate confirmations
Copy link
Member

Choose a reason for hiding this comment

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

Should we match mobile and use:

Temporary mechanism to enable security alerts API prior to release


import { SecurityAlertResponse } from '../../../../../../app/scripts/lib/ppom/types';
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we want to avoid referencing background types in the frontend.

Could we instead update the shared type?


return {
...response,
source: SecurityAlertSource.Local,
Copy link
Member

Choose a reason for hiding this comment

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

We're adding this to the response, but do we also have to update getBlockaidMetricsProps in ui/helpers/utils/metrics.js to add it to the event?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants