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

Malformed URLs crash the entire app with a 500 Error #1351

Closed
3 tasks done
cmaerz opened this issue Sep 19, 2024 · 3 comments · Fixed by #1353
Closed
3 tasks done

Malformed URLs crash the entire app with a 500 Error #1351

cmaerz opened this issue Sep 19, 2024 · 3 comments · Fixed by #1353
Labels
bug Something isn't working

Comments

@cmaerz
Copy link

cmaerz commented Sep 19, 2024

Description

When I use a malformed URL like /soga/ibiza% the app crashed with a

 Error [URIError]: URI malformed
    at decodeURI (<anonymous>)
    at middleware (webpack-internal:///(middleware)/./node_modules/next-intl/dist/development/middleware/middleware.js:24:36)
    at Object.middleware$1 (webpack-internal:///(middleware)/./src/middleware.ts:66:12)

I worked it around with the following portion in middleware.ts

try {
    decodeURI(req.nextUrl.pathname);
  } catch (e) {
    return new Response(new Blob(), { status: 404 });
  }

It also reproducible on the demo Repos :D

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://next-intl-bug-repro-app-router.vercel.app/en/asdafa%

Reproduction description

Steps to reproduce:

  1. Enter a Url Like /en/ibiza%
  2. See the Error

Expected behaviour

Returns a 404, like NextJS normally does.

@cmaerz cmaerz added bug Something isn't working unconfirmed Needs triage. labels Sep 19, 2024
@amannn
Copy link
Owner

amannn commented Sep 19, 2024

Thanks for the report! After some local testing I found that Next.js might also return a 400 status code, maybe depending on if you have a segment like /[locale] where it tries to extract a segment from the pathname.

I've set up #1353 where the invalid request is simply forwarded, letting Next.js handle it. As far as I can tell, in invalid pathname never reaches the app, but is caught by the error handling of Next.js at some level.

Does that sound reasonable to you?

@amannn amannn removed the unconfirmed Needs triage. label Sep 19, 2024
@cmaerz
Copy link
Author

cmaerz commented Sep 19, 2024

Sounds good! Thanks!

Schöne Grüße in die Berge :)

@amannn
Copy link
Owner

amannn commented Sep 19, 2024

Will be out in a minute, schöne Grüße retour! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants