-
Notifications
You must be signed in to change notification settings - Fork 439
fix(backend): Exclude non-GET requests from handshake eligibility #8045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/backend': patch | ||
| --- | ||
|
|
||
| Fix POST requests with `sec-fetch-dest: document` incorrectly triggering handshake redirects, resulting in 405 errors from FAPI. Non-GET requests (e.g. native form submissions) are now excluded from handshake and multi-domain sync eligibility. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,7 +475,9 @@ export const authenticateRequest: AuthenticateRequest = (async ( | |
| } | ||
| } | ||
| const isRequestEligibleForMultiDomainSync = | ||
| authenticateContext.isSatellite && authenticateContext.secFetchDest === 'document'; | ||
| authenticateContext.isSatellite && | ||
| authenticateContext.secFetchDest === 'document' && | ||
| authenticateContext.method === 'GET'; | ||
|
|
||
| /** | ||
| * Begin multi-domain sync flows | ||
|
|
@@ -650,6 +652,7 @@ export const authenticateRequest: AuthenticateRequest = (async ( | |
| // Check for cross-origin requests from satellite domains to primary domain | ||
| const shouldForceHandshakeForCrossDomain = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to the PR, but this check looks off. It looks like it will trigger for any cross origin referrer, regardless of if satellites are involved or not, which does not seem like the intent from the original PR or the comments etc. I wonder if we could tighten that up somehow? 🤔
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ephem this is correct, we currently have no way to know if an app is using satellites here when on a primary (non-satellite) domain, so this is a best effort check. |
||
| !authenticateContext.isSatellite && // We're on primary | ||
| authenticateContext.method === 'GET' && // Only GET navigations (POST form submissions set sec-fetch-dest: document too) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to make sure I understand this correctly. My understanding is that in this scenario we should make a handshake, but we can't. According to #6238, we do the This check bypasses that for POSTs, essentially saying we don't need a handshake for POSTs, which means we might return a different auth state here than the satellite? I'd imagine having the correct auth state would be more important for POSTs, not less though? Removing this check will make it hit the For the specific case we've discussed, the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. This is a case where a handshake would be appropriate if it was a GET navigation request, but it's a POST instead. So yeah, this essentially makes the POST request get handled by the app server (regardless of auth state) instead of forcing a redirect to a handshake endpoint from the Clerk middleware. |
||
| authenticateContext.secFetchDest === 'document' && // Document navigation | ||
| authenticateContext.isCrossOriginReferrer() && // Came from different domain | ||
| !authenticateContext.isKnownClerkReferrer() && // Not from Clerk accounts portal or FAPI | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.