Skip to content
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

feat(nextjs): Detect infinite interstitial redirect loop in middleware #1324

Conversation

anagstef
Copy link
Member

@anagstef anagstef commented Jun 8, 2023

Type of change

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

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • @clerk/chrome-extension
  • gatsby-plugin-clerk
  • build/tooling/chore

Description

  • npm test runs as expected.
  • npm run build runs as expected.

When in development, we want to prevent infinite interstitial redirection loops.
We incrementally set a __clerk_redirection_loop cookie, and after looping 6 times, we throw an error.
We also utilize the referer header to skip the prefetch requests.

Screenshot 2023-06-14 at 4 01 28 PM

@anagstef anagstef requested a review from dimkl June 8, 2023 18:18
@anagstef anagstef self-assigned this Jun 8, 2023
@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2023

🦋 Changeset detected

Latest commit: 64bc208

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

This PR includes changesets to release 1 package
Name Type
@clerk/nextjs 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

@github-actions github-actions bot added the nextjs label Jun 8, 2023
When in development, we want to prevent infinite interstitial redirection loops.
We incrementally set a `__clerk_redirection_loop` cookie, and after looping 6 times, we throw an error.
We also utilize the `referer` header to skip the prefetch requests.
@anagstef anagstef force-pushed the stefanos/js-169-catch-infinite-redirects-and-inform-the-developer branch from c9a0ec8 to 5fede9e Compare June 8, 2023 18:20
Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

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

✅ Great news! Jit hasn't found any security issues in your PR. Good Job! 🏆

@nikosdouvlis
Copy link
Member

!snapshot

@clerk-cookie
Copy link
Collaborator

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

Package Version
@clerk/backend 0.22.0-snap.5fede9e
@clerk/chrome-extension 0.3.8-snap.5fede9e
@clerk/clerk-js 4.45.1-snap.5fede9e
eslint-config-custom 0.3.0
@clerk/clerk-expo 0.17.8-snap.5fede9e
@clerk/fastify 0.4.6-snap.5fede9e
gatsby-plugin-clerk 4.3.7-snap.5fede9e
@clerk/localizations 1.17.1-snap.5fede9e
@clerk/nextjs 4.20.0-snap.5fede9e
@clerk/clerk-react 4.19.0-snap.5fede9e
@clerk/remix 2.6.6-snap.5fede9e
@clerk/clerk-sdk-node 4.10.4-snap.5fede9e
@clerk/shared 0.18.0-snap.5fede9e
@clerk/themes 1.7.5
@clerk/types 3.41.1-snap.5fede9e

Tip: use the snippet copy button below to quickly install the required packages.

# @clerk/backend
npm i @clerk/backend@0.22.0-snap.5fede9e
# @clerk/chrome-extension
npm i @clerk/chrome-extension@0.3.8-snap.5fede9e
# @clerk/clerk-js
npm i @clerk/clerk-js@4.45.1-snap.5fede9e
# eslint-config-custom
npm i eslint-config-custom@0.3.0
# @clerk/clerk-expo
npm i @clerk/clerk-expo@0.17.8-snap.5fede9e
# @clerk/fastify
npm i @clerk/fastify@0.4.6-snap.5fede9e
# gatsby-plugin-clerk
npm i gatsby-plugin-clerk@4.3.7-snap.5fede9e
# @clerk/localizations
npm i @clerk/localizations@1.17.1-snap.5fede9e
# @clerk/nextjs
npm i @clerk/nextjs@4.20.0-snap.5fede9e
# @clerk/clerk-react
npm i @clerk/clerk-react@4.19.0-snap.5fede9e
# @clerk/remix
npm i @clerk/remix@2.6.6-snap.5fede9e
# @clerk/clerk-sdk-node
npm i @clerk/clerk-sdk-node@4.10.4-snap.5fede9e
# @clerk/shared
npm i @clerk/shared@0.18.0-snap.5fede9e
# @clerk/themes
npm i @clerk/themes@1.7.5
# @clerk/types
npm i @clerk/types@3.41.1-snap.5fede9e

@anagstef anagstef marked this pull request as ready for review June 14, 2023 13:25
.changeset/soft-snakes-hope.md Outdated Show resolved Hide resolved
packages/nextjs/src/server/authMiddleware.ts Outdated Show resolved Hide resolved
Copy link
Member

@nikosdouvlis nikosdouvlis left a comment

Choose a reason for hiding this comment

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

very nice :)

packages/nextjs/src/server/authMiddleware.ts Outdated Show resolved Hide resolved
packages/nextjs/src/server/authMiddleware.ts Outdated Show resolved Hide resolved
packages/nextjs/src/server/authMiddleware.ts Outdated Show resolved Hide resolved
packages/nextjs/src/server/authMiddleware.ts Show resolved Hide resolved
@anagstef anagstef force-pushed the stefanos/js-169-catch-infinite-redirects-and-inform-the-developer branch from f9f17ab to fce5282 Compare June 14, 2023 15:54
@anagstef anagstef merged commit 4212b7c into main Jun 14, 2023
@anagstef anagstef deleted the stefanos/js-169-catch-infinite-redirects-and-inform-the-developer branch June 14, 2023 18:16
@clerk-cookie clerk-cookie mentioned this pull request Jun 14, 2023
@clerk-cookie
Copy link
Collaborator

This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@clerk clerk locked as resolved and limited conversation to collaborators Jun 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants