Skip to content

fix(backend): Fix issue with FAPI suffixed cookies disabled - #3789

Merged
dimkl merged 6 commits into
mainfrom
fix/backend-sdk-without-fapi-ff-enabled
Jul 23, 2024
Merged

fix(backend): Fix issue with FAPI suffixed cookies disabled#3789
dimkl merged 6 commits into
mainfrom
fix/backend-sdk-without-fapi-ff-enabled

Conversation

@dimkl

@dimkl dimkl commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

Description

For production instances that use the latest ClerkJS and backend SDKs if the suffixed cookies are disabled in FAPI, in every page refresh a handshake is triggered.
To fix this we should use the un-suffixed cookies when the suffixed client_uat does not exist but the suffixed session exists.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

For production instances that use the latest ClerkJS and backend
SDKs if the FAPI suffixed cookies are disabled, in every page
refresh a handshake is triggered.
To fix this we should use the un-suffixed cookies
when the suffixed client_uat does not exist but the
suffixed session exists.
@dimkl dimkl self-assigned this Jul 23, 2024
@changeset-bot

changeset-bot Bot commented Jul 23, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d8bdf84

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@clerk/backend Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/tanstack-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dimkl

dimkl commented Jul 23, 2024

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @dimkl - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.0.2-snapshot.v22b1fc0
@clerk/backend 1.4.1-snapshot.v22b1fc0
@clerk/chrome-extension 1.1.6-snapshot.v22b1fc0
@clerk/clerk-js 5.10.1-snapshot.v22b1fc0
@clerk/clerk-expo 1.2.9-snapshot.v22b1fc0
@clerk/express 0.0.19-snapshot.v22b1fc0
@clerk/fastify 1.0.21-snapshot.v22b1fc0
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.5.1-snapshot.v22b1fc0
@clerk/nextjs 5.2.6-snapshot.v22b1fc0
@clerk/remix 4.2.5-snapshot.v22b1fc0
@clerk/clerk-sdk-node 5.0.18-snapshot.v22b1fc0
@clerk/tanstack-start 0.1.9-snapshot.v22b1fc0
@clerk/testing 1.2.1-snapshot.v22b1fc0

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@1.0.2-snapshot.v22b1fc0 --save-exact

@clerk/backend

npm i @clerk/backend@1.4.1-snapshot.v22b1fc0 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.1.6-snapshot.v22b1fc0 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.10.1-snapshot.v22b1fc0 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.2.9-snapshot.v22b1fc0 --save-exact

@clerk/express

npm i @clerk/express@0.0.19-snapshot.v22b1fc0 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.21-snapshot.v22b1fc0 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.5.1-snapshot.v22b1fc0 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.2.6-snapshot.v22b1fc0 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.5-snapshot.v22b1fc0 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.18-snapshot.v22b1fc0 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.1.9-snapshot.v22b1fc0 --save-exact

@clerk/testing

npm i @clerk/testing@1.2.1-snapshot.v22b1fc0 --save-exact

Comment thread packages/backend/src/tokens/request.ts Outdated
const url = new URL(`https://${frontendApiNoProtocol}/v1/client/handshake`);
url.searchParams.append('redirect_url', redirectUrl?.href || '');
url.searchParams.append('suffixed_cookies', authenticateContext.suffixedCookies.toString());
url.searchParams.append('suffixed_cookies', 'true');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to revert this because I think its not needed at the moment

For production instances that use the latest ClerkJS and backend
SDKs if the FAPI suffixed cookies are disabled, in every page
refresh a handshake is triggered.
To fix this we should use the un-suffixed cookies when the suffixed
session exists but the suffixed client_uat does not exist.
Comment on lines +218 to +219
// This case can be reproduced for production instances when new ClerkJS and backend SDK
// are used but the FF in FAPI is disabled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This case can be reproduced for production instances when new ClerkJS and backend SDK
// are used but the FF in FAPI is disabled

Comment on lines +216 to +219
// In case of incorrectly setup suffixed cookies (session exists but client_uat missing)
// let's use the un-suffixed cookies to keep the existing behavior.
// This case can be reproduced for production instances when new ClerkJS and backend SDK
// are used but the FF in FAPI is disabled

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In case of incorrectly setup suffixed cookies (session exists but client_uat missing)
// let's use the un-suffixed cookies to keep the existing behavior.
// This case can be reproduced for production instances when new ClerkJS and backend SDK
// are used but the FF in FAPI is disabled
// If a suffixed session cookie exists but the corresponding client_uat cookie is missing, fallback to using
// unsuffixed cookies.
// This handle the scenario where an app has been deployed using an SDK version that supports suffixed
// cookies, but FAPI for its Clerk instance has the feature disabled (eg: if we need to temporarily disable the feature).

@dimkl
dimkl force-pushed the fix/backend-sdk-without-fapi-ff-enabled branch from 22b1fc0 to aef391c Compare July 23, 2024 18:55
@nikosdouvlis
nikosdouvlis marked this pull request as ready for review July 23, 2024 19:03
Comment thread packages/backend/src/tokens/authenticateContext.ts Outdated
Co-authored-by: Stefanos Anagnostou <anagstef@users.noreply.github.com>
@dimkl
dimkl enabled auto-merge (squash) July 23, 2024 19:19
@dimkl
dimkl merged commit 045fb93 into main Jul 23, 2024
@dimkl
dimkl deleted the fix/backend-sdk-without-fapi-ff-enabled branch July 23, 2024 19:31
brkalow pushed a commit that referenced this pull request Jul 24, 2024
Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
Co-authored-by: Stefanos Anagnostou <anagstef@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants