Skip to content

fix(core): enforce https on custom proxy/cdnproxy urls - #1300

Merged
abueide merged 2 commits into
masterfrom
security-audit-fixes-core
Aug 25, 2026
Merged

fix(core): enforce https on custom proxy/cdnproxy urls#1300
abueide merged 2 commits into
masterfrom
security-audit-fixes-core

Conversation

@sunitaprajapati89

Copy link
Copy Markdown
Contributor

Task:
Enforce HTTPS on custom proxy/cdnProxy URLs (write key sent over cleartext) ·

  • Where: packages/core/src/util.ts:261-288 (getURL/validateURL), consumed at SegmentDestination.ts:388 and analytics.ts:383.
  • Problem: getURL() only upgrades to https:// when the host has no scheme. An explicit http:// proxy/cdnProxy is preserved, and validateURL's regex allows https?://. uploadEvents() then POSTs { batch, sentAt, writeKey } — write key and all event PII — in cleartext to that host, exposed to on-path attackers. Default hosts are https, so this only bites with a misconfigured custom proxy, but the SDK permits the downgrade silently.
  • Fix: Reject or warn-and-upgrade http:// proxy/cdnProxy unless an explicit allowInsecureProxy opt-in is set. At minimum log a loud warning. Document that the write key + PII travel in the body.

What changes are done:

-[packages/core/src/util.ts] — getURL now throws on http:// unless allowInsecure=true is passed; logs a console.warn when the opt-in is used
-[packages/core/src/types.ts] — added allowInsecureProxy?: boolean to Config with a doc comment explaining the risk
-[packages/core/src/analytics.ts] — passes this.config.allowInsecureProxy to getURL for the CDN proxy path
-[packages/core/src/plugins/SegmentDestination.ts] — passes config?.allowInsecureProxy to getURL for the upload proxy path
-[packages/core/src/tests/util.test.ts] — two new tests covering the rejection and opt-in paths

@abueide
abueide merged commit 1801a8f into master Aug 25, 2026
11 checks passed
@abueide
abueide deleted the security-audit-fixes-core branch August 25, 2026 20:18
abueide added a commit that referenced this pull request Sep 1, 2026
Root cause of the 83/90 CI failures, and it was never a CI problem.

#1300 (fix(core): enforce https on custom proxy/cdnproxy urls) landed on
master after this branch was cut. getURL now throws on any http:// proxy
unless allowInsecureProxy is set. sdk-e2e-tests hands the SDK its mock
server as http://localhost:PORT, so both getEndpoint and
getEndpointForSettings threw, hit their catch blocks, and fell back to the
production Segment endpoints. Events left for the real api.segment.io, the
mock server received nothing, and all 83 assertions failed as
"expected [] to have a length of N" - one fault, not 83.

Worth noting: this means CI runs have been sending test events to
production Segment under throwaway test-<uuid> write keys.

Every earlier local run passed only because this checkout predated #1300 -
which is also why "works locally, fails in CI" looked like an environment
difference and sent the first diagnostic after an IPv6 red herring. This
branch now merges origin/master, so local runs exercise the same code CI
does.

The CLI is a test driver talking to a local mock, so it opts in explicitly
rather than weakening the check. The warning #1300 emits alongside the flag
is appropriate and left in place.

Verified against current master with the enforcement present:
  with the flag:    88 passed | 2 skipped (13 files)
  without the flag: 0 requests reach the mock, same fallback in stderr

Also removes the temporary diagnostic and its workflow step, having served
its purpose.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
abueide added a commit that referenced this pull request Sep 1, 2026
Same fault as the e2e-cli one, in the mobile example app, and currently
masked by stale build artifacts.

buildClient('yup') is the default client, so useProxy is always true and
proxy/cdnProxy are set to http://localhost:9091/v1 (iOS) and
http://10.0.2.2:9091/v1 (Android) - the Detox mock server. Since #1300
getURL rejects insecure proxy URLs, so both would throw, fall back to the
production Segment endpoints, and leave the mock server with nothing to
assert on. Confirmed by calling the current getURL directly on both URLs:

  http://localhost:9091/v1  -> throws "Insecure HTTP proxy URL rejected..."
  http://10.0.2.2:9091/v1   -> throws "Insecure HTTP proxy URL rejected..."

The reason the Detox suites still pass today is that the installed
artifacts predate the change - the APK was built Jul 24 and the .app Jul 27,
while #1300 landed Aug 25. Every mobile run so far, including the 8/8 iOS
and 7/8 Android results, exercised a month-old SDK. The next rebuild would
have turned both suites red for a reason that has nothing to do with
whatever change triggered the rebuild.

NOT VERIFIED END TO END. Confirming it requires rebuilding the app, and the
build needs the devbox-provided toolchain: gradle reads ANDROID_COMPILE_SDK
/ ANDROID_NDK_VERSION etc. from the environment the plugin sets up, and the
globally installed NDK 23.1.7779620 is too old for RN 0.84 (folly's
F14Table.h needs C++20 std::regular). Rebuild inside devbox and re-run both
suites to close this out.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants