Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 40ef2ce

Browse files
committed
Configuration: made max_headers_size a valid setting.
@JanMikes and @tagur87 on GitHub both reported issues with long URLs that were exceeding the 8192 byte large_header_buffer_size setting, which resulted in a HTTP 431 error (Request Header Fields Too Large). This can be resolved in the code by updating the following line in src/nxt_router.c::nxt_router_conf_create() skcf->large_header_buffer_size = 8192; However, requiring users to modify unit and install custom versions is less than ideal. We could increase the value, but to what? This commit takes the option of allowing the user to set this option in their config. Export large_header_buffer_size to the configuration as 'max_headers_size' which is deemed a more suitable user facing name. large_header_buffer_size is already set by the configuration system in nxt_router.c it just isn't set as a valid config option in nxt_conf_validation.c With this change users can set this option in their config if required by the following "settings": { "http": { "max_headers_size": 16384 } }, It retains its default value of 8192 bytes if this is not set. With this commit, without the above setting or too low a value, with a long URL you get a 431 error. With the above setting set to a large enough value, the request is successful. This also adds a couple of test cases for this new setting. Closes: <#521> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent a3cb07d commit 40ef2ce

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

docs/changes.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ prefer system crypto policy, instead of hardcoding a default.
4343
</para>
4444
</change>
4545

46+
<change type="feature">
47+
<para>
48+
new configuration option 'max_headers_size' for 'settings.http' to set the
49+
maximum allowed size of the HTTP headers (including the request line).
50+
Defaults to 8192 bytes.
51+
</para>
52+
</change>
53+
4654
<change type="feature">
4755
<para>
4856
compatibility with OpenSSL 3.

src/nxt_conf_validation.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[] = {
306306
}, {
307307
.name = nxt_string("idle_timeout"),
308308
.type = NXT_CONF_VLDT_INTEGER,
309+
}, {
310+
.name = nxt_string("max_headers_size"),
311+
.type = NXT_CONF_VLDT_INTEGER,
309312
}, {
310313
.name = nxt_string("body_buffer_size"),
311314
.type = NXT_CONF_VLDT_INTEGER,

src/nxt_router.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ static nxt_conf_map_t nxt_router_http_conf[] = {
14471447
},
14481448

14491449
{
1450-
nxt_string("large_header_buffer_size"),
1450+
nxt_string("max_headers_size"),
14511451
NXT_CONF_MAP_SIZE,
14521452
offsetof(nxt_socket_conf_t, large_header_buffer_size),
14531453
},

test/test_settings.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ def req():
257257
assert 'success' in self.conf({'http': {'idle_timeout': 7}}, 'settings')
258258
assert req()['status'] == 200, 'status idle timeout 2'
259259

260+
def test_settings_max_headers_size(self):
261+
self.load('empty')
262+
263+
assert 'success' in self.conf(
264+
{'http': {'max_headers_size': 16 * 1024}}, 'settings'
265+
)
266+
267+
url = "/" + "0" * 1024 + "/index.html";
268+
assert self.get(url=url)['status'] == 200, 'status size'
269+
270+
url = "/" + "0" * 16 * 1024 + "/index.html";
271+
assert self.get(url=url)['status'] == 431, 'status size max'
272+
260273
def test_settings_max_body_size(self):
261274
self.load('empty')
262275

0 commit comments

Comments
 (0)