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

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"] #24977

Closed
jakst opened this issue May 11, 2021 · 3 comments · Fixed by #33763
Closed

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"] #24977

jakst opened this issue May 11, 2021 · 3 comments · Fixed by #33763
Labels
bug Issue was opened via the bug report template.

Comments

@jakst
Copy link

jakst commented May 11, 2021

What version of Next.js are you using?

10.2.0

What version of Node.js are you using?

12.21.0

What browser are you using?

Chrome

What operating system are you using?

MacOS

How are you deploying your application?

next start on heroku

Describe the Bug

Using some special characters in a URL query key crashes Next and gives a 500 with the following stack trace.

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Location"]
  at ServerResponse.setHeader (_http_outgoing.js:533:3)
  at Object.fn (/app/node_modules/next/dist/next-server/server/next-server.js:53:938)
  at Router.execute (/app/node_modules/next/dist/next-server/server/router.js:25:83)
  at runMicrotasks (<anonymous>)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)
  at async Server.run (/app/node_modules/next/dist/next-server/server/next-server.js:68:1042)
  at async Server.handleRequest (/app/node_modules/next/dist/next-server/server/next-server.js:32:504) {
    code: 'ERR_INVALID_CHAR'
  }

Seems like this has been a problem before in #17907, but was fixed for that set of characters.

Expected Behavior

The Next server should return a 404.

To Reproduce

  • Bootstrap a new app with create-next-app and start it with either next dev or next start
  • Visit the app with for example the following path: http://localhost:3003/u/?%23%0d%0ahrs:hrs (looks like it doesn't crash if you add the query to the root path)
  • Observe the server throwing an Internal server error and returning 500.
@jakst jakst added the bug Issue was opened via the bug report template. label May 11, 2021
@Aviortheking
Copy link

I am having the same issue with ['Refresh'] instead of ['Location']

2021-06-15T07:46:06.094Z	59371c74-5ba8-4fbe-9081-4b3af75c4d1f	ERROR	TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Refresh"]
    at ServerResponse.setHeader (_http_outgoing.js:564:3)
    at handleRedirect (/var/task/node_modules/next/dist/next-server/server/next-server.js:90:1278)
    at Server.renderToHTMLWithComponents (/var/task/node_modules/next/dist/next-server/server/next-server.js:137:683)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Server.renderToHTML (/var/task/node_modules/next/dist/next-server/server/next-server.js:138:1088)
    at async Server.render (/var/task/node_modules/next/dist/next-server/server/next-server.js:75:160)
    at async Object.fn (/var/task/node_modules/next/dist/next-server/server/next-server.js:58:672)
    at async Router.execute (/var/task/node_modules/next/dist/next-server/server/router.js:25:67)
    at async Server.run (/var/task/node_modules/next/dist/next-server/server/next-server.js:68:1042)
    at async Server.handleRequest (/var/task/node_modules/next/dist/next-server/server/next-server.js:32:504) {
  code: 'ERR_INVALID_CHAR'
}
RequestId: 59371c74-5ba8-4fbe-9081-4b3af75c4d1f Error: Runtime exited with error: exit status 1
Runtime.ExitError

@balazsorban44
Copy link
Member

Duplicate of #24047

@balazsorban44 balazsorban44 marked this as a duplicate of #24047 Jan 27, 2022
timneutkens added a commit to timneutkens/next.js that referenced this issue Jan 28, 2022
kodiakhq bot pushed a commit that referenced this issue Jan 28, 2022
Fixes the merge conflicts in #27003

Fixes #24977
Fixes #24047
Closes #27003

Co-Authored-By: Jamie <[email protected]>



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
Fixes the merge conflicts in vercel#27003

Fixes vercel#24977
Fixes vercel#24047
Closes vercel#27003

Co-Authored-By: Jamie <[email protected]>



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
3 participants