Skip to content

fix(client): resolve and trust the page origin when apiHost is empty - #190

Merged
Bccorb merged 1 commit into
mainfrom
fix/same-origin-authorized-fetch
Oct 18, 2026
Merged

Bccorb merged 1 commit into
mainfrom
fix/same-origin-authorized-fetch

Conversation

@Bccorb

@Bccorb Bccorb commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Closes #188. Part of the v0.19 release (fells-code/seamless-auth-api#385).

Why

Since client 0.5.0 (#175), authorizedFetch refused every path for an app that serves /auth on its own origin (apiHost: "", the documented <AuthProvider apiHost=""> setup). The client prefixes a path with apiHost, so with an empty one the path stayed relative; originOf returns null for a relative URL and nothing was trusted. Found by conformance on the Next.js starter (fells-code/seamless-templates#124), which stayed on react 0.15 because of it.

What

  • transport.ts: pageOrigin() reads location.origin, which an injected <base> cannot change (unlike the base URL a relative fetch resolves against). An empty apiHost trusts the page origin
  • createSeamlessAuthClient: a path resolves on apiHost, or on the page origin when apiHost is empty
  • Without a page (server rendering, React Native) an empty apiHost still trusts nothing and sends nothing
  • Patch changeset for @seamless-auth/client

Checks

  • npm run lint, npm run format:check, npm run typecheck: pass
  • npm test: 45 suites, 596 tests (Jest) and 41 (Vitest) pass, including 3 new cases
  • npm run build, npm run check-npm-build: pass
  • Packed the built client and re-ran the issue's reproduction: with location.origin set, authorizedFetch('/api/beta-users') reaches http://localhost:5173/api/beta-users; with no page it still rejects with UntrustedOriginError

authorizedFetch refused every path for a same-origin app (apiHost "")
because the path stayed relative and the origin check could not read an
origin from it.

Closes #188
@Bccorb
Bccorb merged commit e3cf1f9 into main Oct 18, 2026
5 checks passed
@Bccorb
Bccorb deleted the fix/same-origin-authorized-fetch branch October 18, 2026 23:28
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.

fix(client): authorizedFetch refuses every path when apiHost is empty (same-origin apps)

1 participant