Why am I getting 400 errors? Node, Express, ReactJS

家住魔仙堡 提交于 2019-12-25 01:37:35

问题


Recently, i've been receiving 400 errors from my reactJS service urls, but I don't receive them on my other microservices. Here is what I tried:

  1. Looking into express to find out if 400 errors are coming from there, no success.

  2. Digging into react code, no 400 errors should be coming from there.

  3. Looking into the chrome console.... but it has nothing.

  4. It doesn't even look like i'm receiving any logs on my server so it's like it never hit, so no logs there.

My node version is 10.15.3 but all my other microservices are 10.13.0.

Why am I getting 400 errors from my react/express NextJS microservice?


回答1:


In november 2018 a PR was made that was a breaking change to the max header size. Headers can only be 8kb in size.

The node versions affects are v6.15.0, v8.14.0, v10.14.0, v11.3.0 (see https://www.nearform.com/blog/protecting-node-js-from-uncontrolled-resource-consumption-headers-attacks/)

You can do one of two things...

  1. Reduce to v10.13.0

  2. Add a flag --max-http-header-size=10000

Background

To avoid DoS attacks the max size was reduced from 80kb to 8kb. If you have a lot of cookies on your site you will receive a 400 error without much output. Read more about the PR and discussions here: https://github.com/nodejs/node/issues/24692 and here is the PR (https://github.com/nodejs/node/commit/92231a56d9)

Testing

To test this, you can use a curl request with a gigantic cookie that is over 8kb and you should receive a 400 error. After adjusting this max value, it should work.



来源:https://stackoverflow.com/questions/56011525/why-am-i-getting-400-errors-node-express-reactjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!