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

On Vercel, Nuxt v3.11.2 causes infinite redirect when query string contains + is passed #26882

Closed
kakkokari-gtyih opened this issue Apr 22, 2024 · 13 comments · Fixed by #26893 or #27016
Closed

Comments

@kakkokari-gtyih
Copy link

kakkokari-gtyih commented Apr 22, 2024

Environment


  • Operating System: Windows_NT
  • Node Version: v20.10.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: pnpm@8.7.0
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

Repo: https://github.com/kakkokari-gtyih/vercel-infinite-redirect-repor
Vercel (no special configuration): https://vercel-infinite-redirect-repor.vercel.app/

Describe the bug

When query string has +, nuxt causes infinite redirection (302).
This doesn't happen in dev mode or node-server.

Additional context

Parent issue: misskey-dev/misskey-hub-next#154

Logs

"2024-04-22 00:30:22",1713745822077,"vercel-infinite-redirect-repor.vercel.app/","GET",200,"cle1::iad1::pjjcc-1713745822047-aee814268194","['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36']","info","production","master","-","lambda","/__nitro","vercel-infinite-redirect-repor.vercel.app","vercel-infinite-redirect-repor.vercel.app","dpl_6cK8zVKGxDGb3k7oiTMrisa9wTUu",9,"-",105,1024,"-","prj_Qdj1I9VBDr4xU69u4UTIu4hsHYvk","-"
"2024-04-22 00:30:07",1713745807614,"vercel-infinite-redirect-repor.vercel.app/","GET",200,"cle1::iad1::xmd65-1713745807596-23bec9d1cac9","['Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36']","info","production","master","-","lambda","/__nitro","vercel-infinite-redirect-repor.vercel.app","vercel-infinite-redirect-repor.vercel.app","dpl_6cK8zVKGxDGb3k7oiTMrisa9wTUu",9,"-",105,1024,"-","prj_Qdj1I9VBDr4xU69u4UTIu4hsHYvk","-"
"2024-04-22 00:29:10",1713745750119,"vercel-infinite-redirect-repor.vercel.app/","GET",302,"kix1::iad1::gz4v2-1713745750032-44d3bc25b519","['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36']","info","production","master","-","lambda","/__nitro","vercel-infinite-redirect-repor.vercel.app","vercel-infinite-redirect-repor.vercel.app","dpl_6cK8zVKGxDGb3k7oiTMrisa9wTUu",7,"-",105,1024,"-","prj_Qdj1I9VBDr4xU69u4UTIu4hsHYvk","-"
(same logs goes here...)
"2024-04-22 00:28:00",1713745680178,"vercel-infinite-redirect-repor.vercel.app/","GET",302,"kix1::iad1::bg5sl-1713745680084-cb945c746bbd","['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36']","info","production","master","-","lambda","/__nitro","vercel-infinite-redirect-repor.vercel.app","vercel-infinite-redirect-repor.vercel.app","dpl_6cK8zVKGxDGb3k7oiTMrisa9wTUu",9,"-",99,1024,"-","prj_Qdj1I9VBDr4xU69u4UTIu4hsHYvk","-"
"2024-04-22 00:27:53",1713745673375,"vercel-infinite-redirect-repor.vercel.app/","GET",200,"kix1::iad1::m7bsh-1713745672704-59fbb8a60726","['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36']","info","production","master","-","lambda","/__nitro","vercel-infinite-redirect-repor.vercel.app","vercel-infinite-redirect-repor.vercel.app","dpl_6cK8zVKGxDGb3k7oiTMrisa9wTUu",10,"-",98,1024,"-","prj_Qdj1I9VBDr4xU69u4UTIu4hsHYvk","-"
@kakkokari-gtyih kakkokari-gtyih changed the title Nuxt v3.11.2 causes infinite redirect when query string is passed on Vercel On Vercel, Nuxt v3.11.2 causes infinite redirect when query string contains + is passed Apr 22, 2024
@IsraelOrtuno
Copy link
Contributor

IsraelOrtuno commented Apr 22, 2024

This happened to me in the past when including characters like / or + too. Not sure if this is a regression but these issues mention it:

#14316
#15738

@kakkokari-gtyih
Copy link
Author

It was working fine until 3.11.1 and went wrong from 3.11.2, so it should be a recurrence

@manniL
Copy link
Member

manniL commented Apr 22, 2024

cc @huang-julien might be related to the encoding? #26712 ?

@abovedave
Copy link

Similar thing happening on Netlify with /, + works though #26888

@huang-julien
Copy link
Member

I think we'll revert the encoding. wdyt @danielroe ?

@danielroe
Copy link
Member

Yes - and let's add a comment there.

@abovedave
Copy link

abovedave commented Apr 23, 2024

I was just looking to patch our site with the fix in #26893 until it's released, but it looks like the work which was reverted from #26712 hadn't even shipped yet and was scheduled for 3.12.0 - so I'm confused at the fix here, unless I missed something?

@kakkokari-gtyih
Copy link
Author

You can use nightly version to for the patch, or you can also just downgrade to v3.11.1

https://nuxt.com/docs/guide/going-further/nightly-release-channel

@abovedave
Copy link

abovedave commented Apr 23, 2024

FWIW I think #26519 is what introduced the bug in 3.11.2. Specifically this line:

} else if (import.meta.server && to.fullPath !== initialURL && (to.redirectedFrom || !isSamePath(to.fullPath, initialURL))) {
await nuxtApp.runWithContext(() => navigateTo(to.fullPath || '/'))
}

In my testing on Netlify given an example dynamic path /post/1?foo=bar/, the nuxtApp.ssrContext.url has encoded the query string, but the router fullPath does not:

initialURL = /post/1?foo=bar%2F
to.fullPath = /post/1?foo=bar/

Therefore the line !isSamePath(to.fullPath, initialURL) is returning true when it should be false. I was able to patch this by using decodeURIComponent(), although I'm not sure if that is the perfect solution here.

!isSamePath(to.fullPath, decodeURIComponent(initialURL)))

Perhaps Vercel and Netlify both encode values passed differently (encodeURIComponent vs encodeURI?), which might explain why a query string with + works on Netlify but not Vercel.

@manniL manniL reopened this Apr 24, 2024
@manniL
Copy link
Member

manniL commented Apr 24, 2024

Re-opening here for further investigation (cc @danielroe)

Copy link
Member

Nice find - thank you @abovedave 🙏

@calbers-ew
Copy link

We are having a similar issue, but I'm not sure if it's exactly the same thing. A couple of questions...

  1. I tried the nightly build and the issue persisted, should that have worked? Would that actually be a temporary solve for this?
  2. our route works fine on localhost in a web browser, but we have some software that uses an integrated Edge browser, and it gets redirected infinitely there until a "too many redirects" error (using localhost as well). The query string that seems to cause it doesn't have any '/' or '+' characters (http://localhost:3000/?mode=light&ver=1.1.1.1&Mode=active&id=ffb738944d621ac08a1802c6a92ad5d69a625800&font=Segoe%20UI). Does this warrant its own issue, or does it seem similar enough?

@abovedave
Copy link

@calbers-ew if it's this bug causing your issue, downgrading to 3.11.1 should fix it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment