fix(analytics): normalise Segment proxy URL to fix invalid-URL error in 2.23.0 cp-7.78.0#30463
Conversation
…sing a lookahead (=+(?=&|$)). Base64 padding is always optional — decoders infer it from data length, and the proxy server handles both forms. The = separators between key and value are untouched.
|
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. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8cee395. Configure here.
|
The security vulnerability do not apply in this context, so ignoring sonar cloud advisory |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Why no E2E tags are needed:
Why no performance tests are needed:
Performance Test Selection: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #30463 +/- ##
=======================================
Coverage 82.13% 82.14%
=======================================
Files 5488 5488
Lines 147722 147743 +21
Branches 33962 33969 +7
=======================================
+ Hits 121328 121358 +30
+ Misses 18093 18077 -16
- Partials 8301 8308 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|



Summary
@segment/analytics-react-native2.23.0 introduced a strictvalidateURLregex via PR #1157 that only allows[a-zA-Z0-9_.-]in query-param values. The MetaMask Segment proxy URL encodes the write key as standard base64 in a query param (?b=<base64>==), and the trailing=padding characters are rejected by this regex.When the URL fails validation
SegmentDestination.getEndpoint()silently falls back tohttps://api.segment.io/v1/b. Events reach Segment's default endpoint but the proxy write key is only valid throughfn.segmentapis.com, so they are rejected — causing no events to appear in Mixpanel.Change
Added
normalizeProxyUrlinplatform-adapter.tsthat strips trailing=padding from query-param values before passing the URL to the Segment client config.=key–value separator is preserved (the regex uses a lookahead(?=&|$)to match only padding at the end of a param value).TODOto remove once upstream fixes the regex to accept all RFC 3986 query characters.Test plan
yarn jest platform-adapterMade with Cursor
Note
Medium Risk
Moderate risk because it changes how the Segment client is configured and could affect where analytics events are sent if the proxy URL is altered incorrectly, though the change is narrowly scoped and covered by unit tests.
Overview
Fixes Segment proxy URL validation failures by normalizing
SEGMENT_PROXY_URLbefore passing it tocreateClient, stripping trailing base64=padding from query-param values (while preserving key/value separators).Adds focused unit coverage for
normalizeProxyUrlacross common URL shapes (single/double padding, multi-param URLs) and a wiring test to ensurecreatePlatformAdapterpasses the normalizedproxyvalue into Segment client configuration.Reviewed by Cursor Bugbot for commit ee00a41. Bugbot is set up for automated code reviews on this repo. Configure here.