Commit ecbc94e
authored
feat(metrics): add eth-chainlist domain check to isPublicEndpointUrl cp-13.17.0 (#39623)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **Description**
Add eth-chainlist domain checking to isPublicEndpointUrl to improve
coverage for identifying public RPC endpoints in metrics. If a domain is
defined in eth-chainlist (cached), it's considered public and safe to
report.
Initialization only happens in background context to avoid ~300KB memory
footprint in UI.
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
[](https://codespaces.new/MetaMask/metamask-extension/pull/39623?quickstart=1)
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/WPC-354
## **Manual testing steps**
```gherkin
Feature: RPC domain analytics
Scenario: Verify rpc_domain shows actual host when switching to public RPC via banner
# Setup - Add Ink network with local RPC
Given user navigates to Settings → Networks → Add Network
And user adds Ink network (Chain ID: 57073) with local RPC endpoint: http://127.0.0.1:8545
And user also adds public RPC endpoint: https://rpc-qnd.inkonchain.com
And user sets the local RPC as the default endpoint
And user switches to Ink network
# Trigger degraded state
When user disconnects local RPC (or it becomes unavailable)
And user waits for banner showing "Still connecting to Ink..."
# Trigger RPC update from banner
Then the "Update RPC" button appears on the banner
When user clicks "Update RPC" on the banner
And user is navigated to Edit Network screen
And user switches default RPC to https://rpc-qnd.inkonchain.com
# Verify analytics in Segment
When user checks Segment dashboard for "Network Connection Banner RPC Updated" event
Then the event property from_rpc_domain should be "custom" (local RPC is private)
And the event property to_rpc_domain should be "rpc-qnd.inkonchain.com" (known public domain)
Scenario: Verify rpc_domain for Infura networks using Switch to MetaMask default
# Setup - Configure Arbitrum with local RPC
Given user starts a local Ganache server: npx ganache --chain.chainId 42161
And user navigates to Settings → Networks → Arbitrum One
And user adds a new RPC endpoint: http://127.0.0.1:8545
And user sets the local RPC as the default endpoint
# Trigger degraded state
When user stops the Ganache server (Ctrl+C)
And user waits for banner showing "Still connecting to Arbitrum One..."
# Switch to Infura via banner button
Then the "Switch to MetaMask default RPC" button appears on the banner
When user clicks "Switch to MetaMask default RPC"
Then the toast "Updated to MetaMask default" appears
# Verify analytics
When user checks Segment for "Network Connection Banner Switch To MetaMask Default RPC Clicked"
Then rpc_domain should be "custom" (the local RPC being switched from)
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes privacy/analytics sanitization for RPC URLs by expanding
what’s considered “public” and moving the check behind a background RPC
call; misclassification could leak domains to metrics or over-redact
valid public endpoints.
>
> **Overview**
> **Expands `isPublicEndpointUrl` to cover chainlist-known RPC
domains.** The public-endpoint check is moved into
`app/scripts/lib/util.ts`, now optionally allowing any hostname found in
the cached safe chainlist while explicitly filtering out `localhost`, IP
literals (v4/v6), and RFC 6761 special-use/reserved domains.
>
> **Routes public-endpoint checks through the background for UI
metrics.** UI analytics in `useNetworkConnectionBanner` and the networks
form now call `submitRequestToBackground('isPublicEndpointUrl', [url])`
(with added error isolation), and the background controller exposes this
method using the runtime Infura project id. Tests were updated
accordingly, and `ip-regex` was added as a dependency.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
f5769e0. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent b9bd84e commit ecbc94e
File tree
13 files changed
+433
-185
lines changed- app/scripts
- lib
- network-controller
- ui
- hooks
- pages/settings/networks-tab/networks-form
13 files changed
+433
-185
lines changedLines changed: 7 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 27 | + | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
| |||
170 | 167 | | |
171 | 168 | | |
172 | 169 | | |
173 | | - | |
174 | | - | |
| 170 | + | |
| 171 | + | |
175 | 172 | | |
176 | 173 | | |
177 | 174 | | |
| |||
180 | 177 | | |
181 | 178 | | |
182 | 179 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 180 | + | |
187 | 181 | | |
188 | 182 | | |
189 | 183 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
608 | 610 | | |
609 | 611 | | |
610 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
611 | 754 | | |
0 commit comments