Skip to content

Commit

Permalink
fix(backend): Fix infinite redirect loops on handshake for invalid se…
Browse files Browse the repository at this point in the history
…cret key (#3259)

By returning a signed-out state for production instances and throwing an
error on development instances when the secret key is incorrect we avoid
infinite redirect loops.
  • Loading branch information
dimkl committed Apr 25, 2024
1 parent d46ab11 commit 4e5de11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/perfect-pumpkins-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

Fix infinite redirect loops for production instances with incorrect secret keys
5 changes: 4 additions & 1 deletion packages/backend/src/tokens/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ ${error.getFullMessage()}`,
throw new Error(`Clerk: Handshake token verification failed: ${error.getFullMessage()}.`);
}

if (error.reason === TokenVerificationErrorReason.TokenInvalidSignature) {
if (
error.reason === TokenVerificationErrorReason.TokenInvalidSignature ||
error.reason === TokenVerificationErrorReason.InvalidSecretKey
) {
// Avoid infinite redirect loops due to incorrect secret-keys
return signedOut(
authenticateContext,
Expand Down

0 comments on commit 4e5de11

Please sign in to comment.