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

Policy: Payload limits fix on content-length #1266

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed typo on TLS jsonschema [PR #1260](https://github.com/3scale/APIcast/pull/1260) [THREESCALE-6390](https://issues.redhat.com/browse/THREESCALE-6390)
- Fixed host header format on http_ng resty [PR #1264](https://github.com/3scale/APIcast/pull/1264) [THREESCALE-2235](https://issues.redhat.com/browse/THREESCALE-2235)
- Fixed issues on OIDC jwk discovery [PR #1268](https://github.com/3scale/APIcast/pull/1268) [THREESCALE-6913](https://issues.redhat.com/browse/THREESCALE-6913)
- Fixed Payload limit content-length response header [PR #1266](https://github.com/3scale/APIcast/pull/1266) [THREESCALE-6736](https://issues.redhat.com/browse/THREESCALE-6736)


### Added
Expand Down
8 changes: 6 additions & 2 deletions gateway/src/apicast/policy/payload_limits/payload_limit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local new = _M.new
local ngx_exit = ngx.exit
local ngx_say = ngx.say

local PayloadErrMessage = "Payload Too Large"

function _M.new(config)
local self = new(config)
self.request_limit = tonumber(config.request) or 0
Expand All @@ -24,7 +26,7 @@ function _M:access()
if tonumber(ngx.var.content_length) > self.request_limit then
ngx.log(ngx.INFO, "request rejected due to large body")
ngx.status = 413
ngx_say("Payload Too Large")
ngx_say(PayloadErrMessage)
return ngx_exit(413)
end
end
Expand All @@ -43,14 +45,16 @@ function _M:header_filter(context)
ngx.log(ngx.INFO, "Response rejected due to large body")
context.request_limited = true;
ngx.status = 413
ngx.header["Content-Length"] = #PayloadErrMessage
return ngx_exit(413)
end
end

function _M:body_filter(context)
if context.request_limited then
ngx.arg[1] = "Payload Too Large"
ngx.arg[1] = PayloadErrMessage
ngx.arg[2] = true

return
end
end
Expand Down
2 changes: 2 additions & 0 deletions t/apicast-policy-payload_limits.t
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ yay, api backend
--- request
POST /test
--- error_code: 413
--- response_headers
Content-Length: 17
--- response_body eval
"Payload Too Large"
--- no_error_log
Expand Down