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

Next 9 Routing: Requested and resolved page mismatch #9536

Closed
derekdowling opened this issue Nov 26, 2019 · 21 comments
Closed

Next 9 Routing: Requested and resolved page mismatch #9536

derekdowling opened this issue Nov 26, 2019 · 21 comments
Labels
please add a complete reproduction The issue lacks information for further investigation

Comments

@derekdowling
Copy link

derekdowling commented Nov 26, 2019

Bug report

Describe the bug

We encountered an error that isn't especially actionable as a consumer. It would be helpful to either provide more context in the error so it's easier to understand what went wrong, or make the error explain more what we need to do to solve the problem.

It appears to have happened when trying to route /. with Next 9 routing in SSR, though I cannot seem to reproduce it. We have a corresponding /index page as well as a /[foo] page if that's of any help.

I'll try to collect more information if it happens again, but I thought it'd be good to know about since it is puzzling.

Expected behavior

Not sure to be honest.

System information

  • Version of Next.js: 9.1.4

Additional context

Log Dump

Handling request for /.

Error: Requested and resolved page mismatch
at Object.normalizePagePath (<project>/node_modules/next/dist/next-server/server/normalize-page-path.js:16:15)
at getPagePath (<project>/node_modules/next/dist/next-server/server/require.js:22:38)
at Object.requirePage (<project>/node_modules/next/dist/next-server/server/require.js:43:22)
at Object.loadComponents (<project>/node_modules/next/dist/next-server/server/load-components.js:24:36)
at Server.findPageComponents (<project>/node_modules/next/dist/next-server/server/next-server.js:457:40)
at Server.renderToHTML (<project>/node_modules/next/dist/next-server/server/next-server.js:553:21)
at Server.render (<project>/node_modules/next/dist/next-server/server/next-server.js:433:33)
at Object.fn (<project>/node_modules/next/dist/next-server/server/next-server.js:311:32)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Router.execute (<project>/node_modules/next/dist/next-server/server/router.js:25:32)
at async Server.run (<project>/node_modules/next/dist/next-server/server/next-server.js:406:29)
@timneutkens
Copy link
Member

timneutkens commented Nov 26, 2019

This issue is not actionable without a reproduction. It's a security bailout to make sure the require can't resolve outside the app. (and generally shouldn't be ran into).

@mengxuhui
Copy link

I hava this quesion
Error: Requested and resolved page mismatch at Object.normalizePagePath

@mengxuhui
Copy link

how to fix

@timneutkens
Copy link
Member

@mengxuhui As said

This issue is not actionable without a reproduction

@mengxuhui
Copy link

Recently frequent

@timneutkens
Copy link
Member

@mengxuhui as said in my previous message we need a full reproduction to investigate 🙏

@derekdowling
Copy link
Author

derekdowling commented Nov 27, 2019

@timneutkens I am still having issues reproducing locally even with NODE_ENV=production in local development. As best I can tell this happens when people are looking for vulnerabilities:

Sample paths that have caused this error:

/foo/./WEB-INF/web.xml
/admin/./WEB-INF/web.xml
/bar/../WEB-INF/web.xml

@mengxuhui
Copy link

@mengxuhui as said in my previous message we need a full reproduction to investigate 🙏

Error: Requested and resolved page mismatch at Object.normalizePagePath (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/normalize-page-path.js:16:15) at getPagePath (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/require.js:16:38) at Object.requirePage (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/require.js:30:22) at Object.loadComponents (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/load-components.js:15:34) at Server.renderToHTMLWithComponents (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/next-server.js:224:48) at Server.renderToHTML (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/next-server.js:236:37) at Server.render (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/next-server.js:192:33) at Object.fn (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/next-server.js:150:36) at /search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/router.js:23:36 at Server.run (/search/odin/ocm/nodeapp/sgkf-portal/run/node_modules/next-server/dist/server/next-server.js:161:23)

thanks a lot

@timneutkens
Copy link
Member

timneutkens commented Nov 28, 2019

@mengxuhui that is not a reproduction. That is an error you're getting in your particular app and is not actionable for us to look into your problem.

@derekdowling that is expected as we block any path mismatches to ensure people don't traverse up the directory tree etc.

@derekdowling
Copy link
Author

derekdowling commented Nov 28, 2019

@timneutkens should this be an error then, or perhaps a warning? Alternatively, is there a way we can catch this error? We run a custom server so I guess we could wrap Next's handler and then not log if the error message matches this.

For context, our team has a policy of alerting when our server encounters any unhandled error which causes this to be really noisy as our service is constantly being scanned by 3rd parties.

@timneutkens
Copy link
Member

This one isn't unhandled though right? It just renders the 404 page afaik?

@mengxuhui
Copy link

I just don't know the specific reason, so I can ask for help. Errors caught by exceptions

@mengxuhui
Copy link

@timneutkens

@timneutkens
Copy link
Member

We can't investigate without a clear and concise reproduction.

@timneutkens timneutkens added the please add a complete reproduction The issue lacks information for further investigation label Dec 2, 2019
@aviaryan
Copy link
Contributor

I also got this error on my production server but I have no idea why it happened. I am the only one who knows that the website exists and I don't recall visiting it at that time. Was it some kind of bot? I will report with a proper issue if I can replicate it. Until then, here's the trace.

2020-01-12T15:19:36.914133386Z app[web.1]: Error: Requested and resolved page mismatch
2020-01-12T15:19:36.914504843Z app[web.1]:     at Object.normalizePagePath (/app/node_modules/next/dist/next-server/server/normalize-page-path.js:16:15)
2020-01-12T15:19:36.924627903Z app[web.1]:     at getPagePath (/app/node_modules/next/dist/next-server/server/require.js:22:38)
2020-01-12T15:19:36.924659614Z app[web.1]:     at Object.requirePage (/app/node_modules/next/dist/next-server/server/require.js:43:22)
2020-01-12T15:19:36.924664520Z app[web.1]:     at Object.loadComponents (/app/node_modules/next/dist/next-server/server/load-components.js:25:36)
2020-01-12T15:19:36.924668209Z app[web.1]:     at Server.findPageComponents (/app/node_modules/next/dist/next-server/server/next-server.js:508:40)
2020-01-12T15:19:36.924671607Z app[web.1]:     at Server.renderToHTML (/app/node_modules/next/dist/next-server/server/next-server.js:602:21)
2020-01-12T15:19:36.924675098Z app[web.1]:     at Server.render (/app/node_modules/next/dist/next-server/server/next-server.js:489:33)
2020-01-12T15:19:36.924678423Z app[web.1]:     at Object.fn (/app/node_modules/next/dist/next-server/server/next-server.js:348:28)
2020-01-12T15:19:36.924681792Z app[web.1]:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-01-12T15:19:36.924685053Z app[web.1]:     at async Router.execute (/app/node_modules/next/dist/next-server/server/router.js:42:32)

@timneutkens
Copy link
Member

timneutkens commented Jan 13, 2020

Posting a stacktrace is not helpful.

As said

We can't investigate without a clear and concise reproduction.

@Kcin1993
Copy link

I use AWS ELB and meet this issue also.
After changing the ELB from Nano to Micro. This issue is solved.

@flizana
Copy link

flizana commented Feb 15, 2020

I am having the same issue. Getting this error when trying to redirect from my / route to /en/ page. I am using a custom node.js server to redirect requests based on user location to the respective language page (/en/, /es/, etc).

// server.js

server.get('/', indexCtrl.redirectLang)
server.get('*', (req, res) => { return handle(req, res) })


// indexCtrl.redirectLang

...
return res.redirect('/en/')
...

I have a /[lang]/index page. The odd thing is I am getting this error only in production, in development it works fine.

@ijjk
Copy link
Member

ijjk commented Feb 15, 2020

Hi @flizana, the mentioned error message has been updated in the latest canary of Next.js (9.2.2-canary.21), specifically this PR which should give more clarity for what is causing it to show

@xiaohuazheng
Copy link

Error: Requested and resolved page mismatch
at Object.normalizePagePath (/node_modules/next/dist/next-server/server/normalize-page-path.js:16:15)

code:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
function normalizePagePath(page) {
    // If the page is `/` we need to append `/index`, otherwise the returned directory root will be bundles instead of pages
    if (page === '/') {
        page = '/index';
    }
    // Resolve on anything that doesn't start with `/`
    if (page[0] !== '/') {
        page = `/${page}`;
    }
    // Throw when using ../ etc in the pathname
    const resolvedPage = path_1.posix.normalize(page);
    if (page !== resolvedPage) {
        throw new Error('Requested and resolved page mismatch');
    }
    return page;
}
exports.normalizePagePath = normalizePagePath;

you can try check your render pagePath.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests

9 participants