Repository navigation
fix(client): resolve and trust the page origin when apiHost is empty - #190
Merged
Merged
Conversation
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
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #188. Part of the v0.19 release (fells-code/seamless-auth-api#385).
Why
Since client 0.5.0 (#175),
authorizedFetchrefused every path for an app that serves/authon its own origin (apiHost: "", the documented<AuthProvider apiHost="">setup). The client prefixes a path withapiHost, so with an empty one the path stayed relative;originOfreturns 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()readslocation.origin, which an injected<base>cannot change (unlike the base URL a relative fetch resolves against). An emptyapiHosttrusts the page origincreateSeamlessAuthClient: a path resolves onapiHost, or on the page origin whenapiHostis emptyapiHoststill trusts nothing and sends nothing@seamless-auth/clientChecks
npm run lint,npm run format:check,npm run typecheck: passnpm test: 45 suites, 596 tests (Jest) and 41 (Vitest) pass, including 3 new casesnpm run build,npm run check-npm-build: passlocation.originset,authorizedFetch('/api/beta-users')reacheshttp://localhost:5173/api/beta-users; with no page it still rejects withUntrustedOriginError