chore(runway): cherry-pick fix(analytics): normalise Segment proxy URL to fix invalid-URL error in 2.23.0 cp-7.78.0#30496
Merged
Conversation
…L to fix invalid-URL error in 2.23.0 cp-7.78.0 (#30463) ## Summary `@segment/analytics-react-native` 2.23.0 introduced a strict `validateURL` regex via [PR #1157](segmentio/analytics-react-native#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 to `https://api.segment.io/v1/b`. Events reach Segment's default endpoint but the proxy write key is only valid through `fn.segmentapis.com`, so they are rejected — causing **no events to appear in Mixpanel**. ## Change Added `normalizeProxyUrl` in `platform-adapter.ts` that strips trailing `=` padding from query-param values before passing the URL to the Segment client config. - Stripping base64 padding is safe: decoders infer it from data length and the proxy server accepts both forms. - The `=` key–value separator is preserved (the regex uses a lookahead `(?=&|$)` to match only padding at the end of a param value). - Contains a `TODO` to remove once upstream fixes the regex to accept all RFC 3986 query characters. ## Test plan - [ ] Run the app in dev mode and verify analytics events appear in Mixpanel - [ ] Verify no "Invalid URL has been passed" errors in the console - [ ] Run unit tests: `yarn jest platform-adapter` Made with [Cursor](https://cursor.com) <!-- CURSOR_SUMMARY --> --- > [!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_URL` before passing it to `createClient`, stripping trailing base64 `=` padding from query-param values (while preserving key/value separators). > > Adds focused unit coverage for `normalizeProxyUrl` across common URL shapes (single/double padding, multi-param URLs) and a wiring test to ensure `createPlatformAdapter` passes the normalized `proxy` value into Segment client configuration. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ee00a41. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: João Santos <joaosantos15@users.noreply.github.com>
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. |
Contributor
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - PR targets a release branch (release/*) All E2E tests pre-selected. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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 MetaMaskSegment proxy URL encodes the write key as standard base64 in a query
param (
?b=<base64>==), and the trailing=padding characters arerejected by this regex.
When the URL fails validation
SegmentDestination.getEndpoint()silently falls back to
https://api.segment.io/v1/b. Events reachSegment's default endpoint but the proxy write key is only valid through
fn.segmentapis.com, so they are rejected — causing no events toappear in Mixpanel.
Change
Added
normalizeProxyUrlinplatform-adapter.tsthat strips trailing=padding from query-param values before passing the URL to theSegment client config.
and the proxy server accepts both forms.
=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 acceptall RFC 3986 query characters.
Test plan
Mixpanel
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, strippingtrailing base64
=padding from query-param values (while preservingkey/value separators).
Adds focused unit coverage for
normalizeProxyUrlacross common URLshapes (single/double padding, multi-param URLs) and a wiring test to
ensure
createPlatformAdapterpasses the normalizedproxyvalue intoSegment client configuration.
Reviewed by Cursor Bugbot for commit
ee00a41. Bugbot is set up for automated
code reviews on this repo. Configure
here.
Co-authored-by: João Santos joaosantos15@users.noreply.github.com 66f0cb2