next.js: Requests to next internals (/_next/...) should never trigger app routes.
Bug report
Describe the bug / reproduction
We’ve had very time-consuming bug to find. We have pages/[...redirect].js fallback page which purpose is redirecting for languages (it was before Next 10).
Let’s assume next.js does a request to a file /_next/.../my-page.json (via Next Link) and the file doesn’t exist. This happens when page was rebuilt and we have new build ID and user still keeps old session in the browser. In that scenario, next.js will trigger /[...redirect].js route, although it’s pretty obvious that none of the /_next/... calls should really do this.
Because of that, instead of 404 for /_next/.../my-page.json which would trigger hard reload (which would in turn reset build ID to the new one), we get something that is completely random because our [...redirect].js got /_next/.../my-page.json path which it didn’t even take into account. This has far reaching consequences of weird and unexpected behaviours.
Expected behavior
If /_next/.../my-page.json doesn’t exist, next.js should simply return 404. Paths from /_next should never trigger app routing.
System information
- OS: any
- Browser: any
- Version of Next.js: 9.5.3
- Version of Node.js: (vercel default)
- Deployment: Vercel
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 18 (6 by maintainers)
Naveed
On Fri, May 27, 2022, 8:16 PM Igo Lapa @.***> wrote:
I have a similar problem but different. I filled in the template for clarity:
Bug report
To Reproduce
pages/books/[id].tsx{ notFound: true }from gSSP if the page does not exist (if the app couldn’t find a book with that id)/_next/data/[hash]/book/1234.json) is called with a non existing id (so gSSP returnsnotFound) it returns the fully built 404 page instead of a JSON response.Describe the bug
Next internal API routes return an HTML response when gSPP returns
{ notFound: true }. In normal app usage, this is not a real problem but we had a user try to enumerate all endpoints (which is not protected given that all that info is public, so we don’t mind the enumeration) it caused unnecessary load and errors for our APP.Expected behavior
When a data route returns 404 it doesn’t include HTML
System information
Is this related enough or should I open a new ticket?