Open VictorGlindasPaf opened 1 year ago
I did some basic debugging. The url above is redirected like this:
/image/https://i.imgur.com/V7WhMQt.jpeg -> /image/https:/i.imgur.com/V7WhMQt.jpeg
It removed the double slash (which looks like by design), but after that it continues redirecting to /image/https:/i.imgur.com/V7WhMQt.jpeg
forever.
The redirect loop occurs here: https://github.com/vercel/next.js/blob/12e77ca/packages/next/src/server/base-server.ts#L650-L661
If I visit /http:/foo
the req.url
at that point has been expanded to /http://foo
. So the regex check detects two slashes and trigger a redirect. However, the url did never contain two slashes in the first place, they have been added internally somewhere before that point. So the redirect redirects to the same url over and over.
any fixes ?
Verify canary release
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/proud-haze-ylj2wz?file=%2Fpackage.json%3A21%2C4
To Reproduce
Go to the codesandbox, and pop open the network console.
Describe the Bug
When rewriting a url that contains multiple slashes, it gets stuck in an infinite loop.
For example
/image/https://i.imgur.com/V7WhMQt.jpeg
For a real-life use case example for this, cloudflare image optimization requires us to pass the image source as part of the url.
Expected Behavior
The image should not be redirected infinitely.
NEXT-1488