NodeJS & HTTP Error Code 431 Request Header Fields
I recently discovered error responses from a Node JS microservice with the HTTP error "431 Request Header Fields Too Large", but at first it seemed to be intermittent, depending on the test environment used. Further investigation revealed it to be a Node setting for maximum header size as well as a Node JS version change and some large cookies.
Error 431 Request Header Fields Too Large HTTP error indicates that the total size of the request headers (including cookies) is too large for the web server to accept. This usually happens when a large cookie has been established to maximize the request size.
In 2018, Node (version 11.6.0) was updated to address a security vulnerability in this area — Denial of Service with Large HTTP Headers (CVE-2018–12121), which resulted in the default maximum request header size being reduced to 8kb (from 16kb), interestingly 8kb was chosen because it was the default for NGINX at the time. The default limit was eventually increased to 16kb in v13.13.0, meaning that if you happened to be running on a version of Node between 11.6 and 13.13, you would be facing the 8kb limit, but not on versions before or after those versions, but on 16kb — which is what I recently ran into.
If the default maximum header size for your node installation isn't working for you, -max-http-header-size
it's easy to configure a new value using the config parameter.
--max-http-header-size=16250
Of course, we should not set this value too high, but should configure it as low as possible for our specific application.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Node.js 发送文件到客户端
Publish Date:2023/03/27 Views:337 Category:Node.js
-
在本文中,我们将学习如何在 Node.js 中向客户端发送文件。
Node.js 中的 HTTP 发送 POST 请求
Publish Date:2023/03/27 Views:457 Category:Node.js
-
在本文中,我们将学习如何使用 Node.js 使用第三方包发出发送 post 请求。
在 Node.js 中调用 REST API
Publish Date:2023/03/27 Views:171 Category:Node.js
-
在本篇文章中,我们将学习如何在 Node.js 中调用 REST API。
Node.js 中的 AJAX 调用
Publish Date:2023/03/27 Views:104 Category:Node.js
-
在本篇文章中,我们将了解 Node.js 中的 AJAX post 请求。
在 Node.js 中执行 Shell 脚本
Publish Date:2023/03/27 Views:280 Category:Node.js
-
在本文中,我们将学习如何使用 Node.js 执行 shell 脚本。
在 Node.js 中编码 URL
Publish Date:2023/03/27 Views:406 Category:Node.js
-
在这篇简短的文章中,我们将学习如何在 Node.js 中进行 URL 编码。
在 Node.js 中编码 Base64
Publish Date:2023/03/27 Views:281 Category:Node.js
-
在本文中,我们将学习如何在 Node.js 中将字符串或文本转换为 base64。
Node.js 与 React JS 的比较
Publish Date:2023/03/27 Views:175 Category:Node.js
-
本文比较和对比了两种编程语言,Node.js 和 React。React 和 Node.js 都是开源 JavaScript 库的示例。 这些库用于构建用户界面和服务器端应用程序。