Skip to content

Invalid Accept-Language header will crash the server #22329

@indeedhat

Description

@indeedhat

What version of Next.js are you using?

10.0.7

What version of Node.js are you using?

15.6.0

What browser are you using?

N/A

What operating system are you using?

Docker: node:15.6.0-alpine3.11

How are you deploying your application?

next start

Describe the Bug

If the server receives a request with an invalid Acceot-Language header it crashes due to an un caught exception

(node:18) UnhandledPromiseRejectionWarning: Error: Invalid accept-language header
    at Object.internals.parse (/app/node_modules/@hapi/accept/lib/header.js:144:28)
    at Object.exports.selections (/app/node_modules/@hapi/accept/lib/header.js:21:22)
    at Object.exports.selection (/app/node_modules/@hapi/accept/lib/header.js:12:32)
    at Object.exports.<computed> [as language] (/app/node_modules/@hapi/accept/lib/index.js:29:53)
    at DevServer.handleRequest (/app/node_modules/next/dist/next-server/server/next-server.js:19:265)
    at Server.emit (events.js:315:20)
    at parserOnIncoming (_http_server.js:790:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
(node:18) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 503)

Expected Behavior

It not to crash

To Reproduce

  • Start your server
  • send a curl request at it with an invalid Accept-Language header \
curl https://my.next-project.com -H 'Accept-Language: ldfir;'
  • the server crashes

The error will also happen with the dev server next dev but the server doesnt actually crash in that case

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions