Skip to content

refactor: Remove usage of regex for portfolio URLs#8674

Merged
sethkfman merged 17 commits intomainfrom
ellul/remove-regex-portfolio
Apr 10, 2024
Merged

refactor: Remove usage of regex for portfolio URLs#8674
sethkfman merged 17 commits intomainfrom
ellul/remove-regex-portfolio

Conversation

@NEllusion
Copy link
Copy Markdown
Contributor

@NEllusion NEllusion commented Feb 22, 2024

Description

This PR addresses a few issues related to how we were using regex expressions. In particular, how we were using URLs in regex statements. This is due to the fact that if we use a URL in a regex statement without escaping it, the periods get interpreted as regex wildcard characters.

In this case, it means that URLs such as https://portfolioxmetamask.io would be be interpreted by MetaMask as being a valid portfolio URL. This could open up the door to phishing situations or unexpected behaviour.

Rather than attempting to make the regex safe to use, I opted to re-write the code without the need for regex. This uses built in Javascript URL for more accurate comparisons.

Related issues

https://github.com/MetaMask/mobile-planning/issues/1571

Manual testing steps

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@github-actions
Copy link
Copy Markdown
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.

@NEllusion NEllusion changed the title Remove usage of regex for portfolio URLs chore: Remove usage of regex for portfolio URLs Feb 22, 2024
@NEllusion NEllusion added the team-mobile-platform Mobile Platform team label Feb 22, 2024
@NEllusion NEllusion changed the title chore: Remove usage of regex for portfolio URLs refactor: Remove usage of regex for portfolio URLs Feb 22, 2024
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Feb 22, 2024
@NEllusion NEllusion force-pushed the ellul/remove-regex-portfolio branch from 1ec88e8 to 6cf64a3 Compare February 22, 2024 16:58
@NEllusion NEllusion marked this pull request as ready for review February 22, 2024 17:00
@NEllusion NEllusion requested a review from a team as a code owner February 22, 2024 17:00
@github-actions
Copy link
Copy Markdown
Contributor

E2E test started on Bitrise: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/98ba3fbe-2b24-456e-9467-f66a49fde58c
You can also kick off another Bitrise E2E smoke test by removing and re-applying the (Run Smoke E2E) label

@NEllusion NEllusion force-pushed the ellul/remove-regex-portfolio branch from 6cf64a3 to 5a03866 Compare February 22, 2024 17:07
@NEllusion
Copy link
Copy Markdown
Contributor Author

Quality Gate Failed Quality Gate failed

Failed conditions 8.8% Duplication on New Code (required ≤ 5%)

See analysis details on SonarCloud

I also noticed this duplicate code but its outside the scope of this change to refactor the duplicated components

tommasini
tommasini previously approved these changes Feb 22, 2024
Copy link
Copy Markdown
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 27, 2024

Codecov Report

Attention: Patch coverage is 65.00000% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 46.00%. Comparing base (d1d5c00) to head (504edcc).

Files Patch % Lines
app/components/UI/Tokens/index.tsx 0.00% 3 Missing ⚠️
app/components/UI/AccountOverview/index.js 0.00% 2 Missing ⚠️
app/components/UI/Bridge/utils/useGoToBridge.ts 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8674      +/-   ##
==========================================
+ Coverage   45.98%   46.00%   +0.01%     
==========================================
  Files        1273     1274       +1     
  Lines       31342    31352      +10     
  Branches     3213     3215       +2     
==========================================
+ Hits        14414    14424      +10     
  Misses      16079    16079              
  Partials      849      849              

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

@NEllusion NEllusion added the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Mar 6, 2024
NicolasMassart
NicolasMassart previously approved these changes Mar 20, 2024
Copy link
Copy Markdown
Contributor

@NicolasMassart NicolasMassart left a comment

Choose a reason for hiding this comment

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

Awesome!

@NEllusion
Copy link
Copy Markdown
Contributor Author

@NicolasMassart looks like theres a conflict, i'll re-tag you once I rebase!

sethkfman and others added 11 commits April 4, 2024 09:16
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2024

1 similar comment
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2024

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 17ae813
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/7c8529bc-2b66-4bbe-bfb9-8ae0f50bdb59

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

sethkfman
sethkfman previously approved these changes Apr 10, 2024
Copy link
Copy Markdown
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

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

LGTM

@sonarqubecloud
Copy link
Copy Markdown

@sethkfman sethkfman merged commit ef475b7 into main Apr 10, 2024
@sethkfman sethkfman deleted the ellul/remove-regex-portfolio branch April 10, 2024 22:07
@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2024
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Apr 10, 2024
@metamaskbot metamaskbot added the release-7.21.0 Issue or pull request that will be included in release 7.21.0 label Apr 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-7.21.0 Issue or pull request that will be included in release 7.21.0 team-mobile-platform Mobile Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants