fix: UID cookie isn't accessible/created when in embed as it is third party context.#19859
Merged
Merged
Conversation
|
@gopoto is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
| // We need this cookie to be accessible from embeds where the booking flow is displayed within an iframe on a different origin. | ||
| // For third‑party iframe contexts (embeds on other sites), browsers require SameSite=None and Secure to make the cookie available. | ||
| // For local development on http://localhost we fall back to SameSite=Lax to avoid requiring https during development. | ||
| const useSecureCookies = WEBAPP_URL?.startsWith("https://"); |
Member
There was a problem hiding this comment.
I don't think WEBAPP_URL could be undefined
Suggested change
| const useSecureCookies = WEBAPP_URL?.startsWith("https://"); | |
| const useSecureCookies = WEBAPP_URL.startsWith("https://"); |
Contributor
Author
There was a problem hiding this comment.
Dropped the optional chain on WEBAPP_URL — it always has a value so we can safely call startsWith.
…as it is third party context.
36244aa to
3404c54
Compare
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (03/11/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add community label" took an action on this PR • (03/11/25)1 label was added to this PR based on Keith Williams's automation. |
hariombalhara
approved these changes
Mar 18, 2025
Contributor
E2E results are ready! |
| }, | ||
| })); | ||
|
|
||
| // A tiny helper to build a canned handler context with stubbed Prisma methods. |
Contributor
There was a problem hiding this comment.
These comments are redundant since the code is self-explanatory
keithwillcode
approved these changes
Mar 18, 2025
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.
What does this PR do?
We currently use a
uidcookie to both mark a reserved slot and gate the “Slot no longer available” rollout. On embeds, however, that cookie never gets set becauseSameSite=Laxcookies aren’t sent from<iframe>s and other third‑party contexts. This has two side–effects:reserveSlotcall gets a freshuidand we never “unlink” the previous provisional selection.This patch sets the
uidcookie toSameSite=None; Securein production (WEBAPP_URLstarts withhttps://) and gracefully falls back toSameSite=Laxlocally so you can still develop onhttp://localhost. Safari will still need special handling, but moving toSameSite=Noneunblocks Chrome and other major browsers.A small unit test has been added under
packages/trpc/server/routers/viewer/slotsto exercise that the cookie emitted byreserveSlotHandlerpicks up the right security flags for both HTTP and HTTPS environments.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
WEBAPP_URL(or pointNEXT_PUBLIC_WEBAPP_URLat an HTTPS origin).uidcookie should now be present withSameSite=NoneandSecureset.uidis now visible.For local development (
http://localhost:3000), cookies continue to beSameSite=Lax/non‑secure so you won’t be forced to configure HTTPS.