You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature: ngx.req.get_post_args(), ngx.req.get_uri_args(), ngx.req.get_headers(), ngx.resp.get_headers(), and ngx.decode_args() now would return an error string, "truncated", when the input exceeds the max_args/max_headers limits.
bugfix: ngx.resp.get_headers(): the max_headers limit did not cover builtin headers.
Returns a Lua table holding all the current response headers for the current request.
4181
4181
4182
4182
```lua
4183
4183
4184
-
localh=ngx.resp.get_headers()
4184
+
localh, err=ngx.resp.get_headers()
4185
+
4186
+
iferr=="truncated" then
4187
+
-- one can choose to ignore or reject the current response here
4188
+
end
4189
+
4185
4190
fork, vinpairs(h) do
4186
4191
...
4187
4192
end
4188
4193
```
4189
4194
4190
4195
This function has the same signature as [ngx.req.get_headers](#ngxreqget_headers) except getting response headers instead of request headers.
4191
4196
4197
+
Note that a maximum of 100 response headers are parsed by default (including those with the same name) and that additional response headers are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
4198
+
4192
4199
This API was first introduced in the `v0.9.5` release.
4193
4200
4194
4201
[Back to TOC](#nginx-api-for-lua)
@@ -4461,7 +4468,7 @@ See also [ngx.req.set_uri](#ngxreqset_uri).
@@ -4471,7 +4478,12 @@ Returns a Lua table holding all the current request URL query arguments.
4471
4478
4472
4479
location = /test {
4473
4480
content_by_lua_block {
4474
-
local args = ngx.req.get_uri_args()
4481
+
local args, err = ngx.req.get_uri_args()
4482
+
4483
+
if err == "truncated" then
4484
+
-- one can choose to ignore or reject the current request here
4485
+
end
4486
+
4475
4487
for key, val in pairs(args) do
4476
4488
if type(val) == "table" then
4477
4489
ngx.say(key, ": ", table.concat(val, ", "))
@@ -4523,7 +4535,7 @@ Updating query arguments via the nginx variable `$args` (or `ngx.var.args` in Lu
4523
4535
```lua
4524
4536
4525
4537
ngx.var.args="a=3&b=42"
4526
-
localargs=ngx.req.get_uri_args()
4538
+
localargs, err=ngx.req.get_uri_args()
4527
4539
```
4528
4540
4529
4541
Here the `args` table will always look like
@@ -4535,20 +4547,23 @@ Here the `args` table will always look like
4535
4547
4536
4548
regardless of the actual request query string.
4537
4549
4538
-
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks.
4550
+
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
4539
4551
4540
4552
However, the optional `max_args` function argument can be used to override this limit:
4541
4553
4542
4554
```lua
4543
4555
4544
-
localargs=ngx.req.get_uri_args(10)
4556
+
localargs, err=ngx.req.get_uri_args(10)
4557
+
iferr=="truncated" then
4558
+
-- one can choose to ignore or reject the current request here
4559
+
end
4545
4560
```
4546
4561
4547
4562
This argument can be set to zero to remove the limit and to process all request arguments received:
4548
4563
4549
4564
```lua
4550
4565
4551
-
localargs=ngx.req.get_uri_args(0)
4566
+
localargs, err=ngx.req.get_uri_args(0)
4552
4567
```
4553
4568
4554
4569
Removing the `max_args` cap is strongly discouraged.
@@ -4569,6 +4584,11 @@ Returns a Lua table holding all the current request POST query arguments (of the
4569
4584
content_by_lua_block {
4570
4585
ngx.req.read_body()
4571
4586
local args, err = ngx.req.get_post_args()
4587
+
4588
+
if err == "truncated" then
4589
+
-- one can choose to ignore or reject the current request here
4590
+
end
4591
+
4572
4592
if not args then
4573
4593
ngx.say("failed to get post args: ", err)
4574
4594
return
@@ -4637,20 +4657,23 @@ That is, they will take Lua boolean values `true`. However, they are different f
4637
4657
4638
4658
Empty key arguments are discarded. `POST /test` with body `=hello&=world` will yield empty outputs for instance.
4639
4659
4640
-
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks.
4660
+
Note that a maximum of 100 request arguments are parsed by default (including those with the same name) and that additional request arguments are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
4641
4661
4642
4662
However, the optional `max_args` function argument can be used to override this limit:
4643
4663
4644
4664
```lua
4645
4665
4646
-
localargs=ngx.req.get_post_args(10)
4666
+
localargs, err=ngx.req.get_post_args(10)
4667
+
iferr=="truncated" then
4668
+
-- one can choose to ignore or reject the current request here
4669
+
end
4647
4670
```
4648
4671
4649
4672
This argument can be set to zero to remove the limit and to process all request arguments received:
4650
4673
4651
4674
```lua
4652
4675
4653
-
localargs=ngx.req.get_post_args(0)
4676
+
localargs, err=ngx.req.get_post_args(0)
4654
4677
```
4655
4678
4656
4679
Removing the `max_args` cap is strongly discouraged.
@@ -4659,15 +4682,20 @@ Removing the `max_args` cap is strongly discouraged.
Returns a Lua table holding all the current request headers.
4667
4690
4668
4691
```lua
4669
4692
4670
-
localh=ngx.req.get_headers()
4693
+
localh, err=ngx.req.get_headers()
4694
+
4695
+
iferr=="truncated" then
4696
+
-- one can choose to ignore or reject the current request here
4697
+
end
4698
+
4671
4699
fork, vinpairs(h) do
4672
4700
...
4673
4701
end
@@ -4698,20 +4726,24 @@ the value of `ngx.req.get_headers()["Foo"]` will be a Lua (array) table such as:
4698
4726
{"foo", "bar", "baz"}
4699
4727
```
4700
4728
4701
-
Note that a maximum of 100 request headers are parsed by default (including those with the same name) and that additional request headers are silently discarded to guard against potential denial of service attacks.
4729
+
Note that a maximum of 100 request headers are parsed by default (including those with the same name) and that additional request headers are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
4702
4730
4703
4731
However, the optional `max_headers` function argument can be used to override this limit:
4704
4732
4705
4733
```lua
4706
4734
4707
-
localheaders=ngx.req.get_headers(10)
4735
+
localheaders, err=ngx.req.get_headers(10)
4736
+
4737
+
iferr=="truncated" then
4738
+
-- one can choose to ignore or reject the current request here
4739
+
end
4708
4740
```
4709
4741
4710
4742
This argument can be set to zero to remove the limit and to process all request headers received:
4711
4743
4712
4744
```lua
4713
4745
4714
-
localheaders=ngx.req.get_headers(0)
4746
+
localheaders, err=ngx.req.get_headers(0)
4715
4747
```
4716
4748
4717
4749
Removing the `max_headers` cap is strongly discouraged.
@@ -5489,13 +5521,13 @@ This method was first introduced in the `v0.3.1rc27` release.
Decodes a URI encoded query-string into a Lua table. This is the inverse function of [ngx.encode_args](#ngxencode_args).
5497
5529
5498
-
The optional `max_args` argument can be used to specify the maximum number of arguments parsed from the `str` argument. By default, a maximum of 100 request arguments are parsed (including those with the same name) and that additional URI arguments are silently discarded to guard against potential denial of service attacks.
5530
+
The optional `max_args` argument can be used to specify the maximum number of arguments parsed from the `str` argument. By default, a maximum of 100 request arguments are parsed (including those with the same name) and that additional URI arguments are silently discarded to guard against potential denial of service attacks. Since `v0.10.13`, when the limit is exceeded, it will return a second value which is the string `"truncated"`.
5499
5531
5500
5532
This argument can be set to zero to remove the limit and to process all request arguments received:
5501
5533
@@ -8149,7 +8181,7 @@ This Lua module does not ship with this ngx_lua module itself rather it is shipp
0 commit comments