-
Notifications
You must be signed in to change notification settings - Fork 408
fix(backend): Prevent excessive handshakes #6635
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
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 | ||
| --- | ||
|
|
||
| Fixes an issue where a handshake would trigger more than intended in development. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,7 @@ export class HandshakeService { | |
| const newUrl = new URL(this.authenticateContext.clerkUrl); | ||
| newUrl.searchParams.delete(constants.QueryParameters.Handshake); | ||
| newUrl.searchParams.delete(constants.QueryParameters.HandshakeHelp); | ||
| newUrl.searchParams.delete(constants.QueryParameters.DevBrowser); | ||
| headers.append(constants.Headers.Location, newUrl.toString()); | ||
| headers.set(constants.Headers.CacheControl, 'no-store'); | ||
| } | ||
|
|
@@ -323,7 +324,7 @@ ${developmentError.getFullMessage()}`, | |
|
|
||
| const newCounterValue = this.authenticateContext.handshakeRedirectLoopCounter + 1; | ||
| const cookieName = constants.Cookies.RedirectCount; | ||
| headers.append('Set-Cookie', `${cookieName}=${newCounterValue}; SameSite=Lax; HttpOnly; Max-Age=3`); | ||
| headers.append('Set-Cookie', `${cookieName}=${newCounterValue}; SameSite=Lax; HttpOnly; Max-Age=2`); | ||
|
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. 3 was an arbitrary choice here, I'm reducing to 2 to mitigate the case where someone switches between orgs quickly when using org url sync |
||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -386,7 +386,7 @@ export const authenticateRequest: AuthenticateRequest = (async ( | |
| if (!mustActivate) { | ||
| return null; | ||
| } | ||
| if (authenticateContext.handshakeRedirectLoopCounter > 0) { | ||
| if (authenticateContext.handshakeRedirectLoopCounter >= 3) { | ||
|
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. Again, reducing the case where someone might be switching quickly. this should help, in addition to the |
||
| // We have an organization that needs to be activated, but this isn't our first time redirecting. | ||
| // This is because we attempted to activate the organization previously, but the organization | ||
| // must not have been valid (either not found, or not valid for this user), and gave us back | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Was there any reason we used to delete it from the clerk-js side only or just an omission?