Skip to content

feat: refuse to mount on insecure (plain HTTP) host pages (0.8.2)#103

Open
fuhrysteve wants to merge 1 commit into
masterfrom
fuhry/secure-context-guard
Open

feat: refuse to mount on insecure (plain HTTP) host pages (0.8.2)#103
fuhrysteve wants to merge 1 commit into
masterfrom
fuhry/secure-context-guard

Conversation

@fuhrysteve

@fuhrysteve fuhrysteve commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

StreamConnect() now checks window.isSecureContext at init and refuses to mount if the host page is not a secure context. The browser-level secure-context check returns true on HTTPS pages and on the loopback hosts (localhost, 127.0.0.1, [::1]) — same set the backend /sdk-api/* CORS policy allows — so local development against vite, webpack-dev-server, etc. is unaffected.

Motivation

The SDK transmits health-plan member credentials. The backend will (separately, in a coordinated PR) require HTTPS for the CORS policy that gates /sdk-api/*. Without a client-side check, an integration loaded into a plain-HTTP page hits a generic CORS-blocked error in the browser console on the first API call, with no actionable explanation of the underlying cause.

The init-time guard fails fast with a clear console error naming the exact offending origin, calls the optional handleInitErrors callback with the same message, and links to https://developers.tpastream.com/connect/origin-policy explaining the requirement and the fix.

What changes for integrators

  • HTTPS host pages: no change.
  • localhost / 127.0.0.1 / [::1] dev: no change.
  • Plain-HTTP host pages on other hostnames: SDK refuses to mount. Console error is descriptive and points at the docs.

Tests

This repo has no JS test runner today — npm test runs lint (biome) + types (tsc) only. Both pass. The guard is also covered indirectly by:

  • The bundled sdk.js output emitting the secure-context check + the docs URL.
  • The server-side test suite verifying the equivalent policy (companion PR).

Adding a vitest setup is a worthwhile follow-up but out of scope for this change.

Versioning

Patch bump 0.8.1 → 0.8.2. Additive guard, no API change.

CHANGELOG entry included.

`StreamConnect()` now checks `window.isSecureContext` at init and
refuses to mount if the host page is not a secure context. The
browser-level secure-context check returns true on HTTPS pages and
on the loopback hosts (`localhost`, `127.0.0.1`, `[::1]`) — same
set the backend `/sdk-api/*` CORS policy allows — so local
development against `vite`, `webpack-dev-server`, etc. is
unaffected.

The previous behavior on a plain-HTTP host page was a generic
CORS-blocked error in the browser console on the first
`/sdk-api/*` request with no actionable explanation. The SDK now
fails fast at init time with a clear console error naming the
exact origin, calls the optional `handleInitErrors` callback with
the same message, and links to
https://developers.tpastream.com/connect/origin-policy
which explains the requirement and how to fix it.

The SDK transmits health-plan member credentials; sending those
over plain HTTP would expose them in transit. Defense in depth:
the browser-side guard catches the misconfiguration with a
useful error, the server-side CORS regex enforces it as a hard
gate.

This repo has no JS test runner today (`npm test` runs lint +
types only), so the guard is covered by the build emitting the
secure-context string into the bundled output and by the
server-side test suite verifying the equivalent policy. Adding a
vitest setup is out of scope for this change.
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.

1 participant