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

Backport 2.14 THREESCALE-10224 CVE-2023-44487 http/2 rapid reset #1422

Merged
merged 11 commits into from
Nov 2, 2023
Prev Previous commit
Next Next commit
enable lua_check_client_abort
Makes HTTP2 reset streams to be accounted and handled by apicast. Ref CVE-2023-44487
  • Loading branch information
eguzki committed Nov 2, 2023
commit b52ccf01d042aae576e706eb156ca8d3e7879d28
2 changes: 2 additions & 0 deletions gateway/conf.d/apicast.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set_by_lua_block $deployment {
return require('apicast.user_agent').deployment()
}

lua_check_client_abort on;

# TODO: enable in the future when we support SSL
# ssl_certificate_by_lua_block { require('apicast.executor').call() }
# ssl_session_fetch_by_lua_block { require('apicast.executor').call() }
Expand Down
22 changes: 21 additions & 1 deletion gateway/src/apicast/policy/apicast/apicast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ end

function _M.cleanup()
-- now abort all the "light threads" running in the current request handler
ngx.log(ngx.INFO, "client closed the (downstream) connection prematurely.")
ngx.exit(499)
end

function _M:rewrite(context)
ngx.on_abort(self.cleanup)
ngx.log(ngx.INFO, "registering on abort")
local ok, err = ngx.on_abort(self.cleanup)
if not ok then
ngx.log(ngx.ERR, "failed to register the on_abort callback: ", err)
ngx.exit(500)
end

-- load configuration if not configured
-- that is useful when lua_code_cache is off
Expand Down Expand Up @@ -87,6 +93,13 @@ function _M:post_action(context)
end

function _M:access(context)
ngx.log(ngx.INFO, "registering on abort")
local ok, err = ngx.on_abort(self.cleanup)
if not ok then
ngx.log(ngx.ERR, "failed to register the on_abort callback: ", err)
ngx.exit(500)
end

if context.skip_apicast_access then return end

-- Flag to run post_action() only when access() was executed.
Expand All @@ -108,6 +121,13 @@ function _M:access(context)
end

function _M:content(context)
ngx.log(ngx.INFO, "registering on abort")
local ok, err = ngx.on_abort(self.cleanup)
if not ok then
ngx.log(ngx.ERR, "failed to register the on_abort callback: ", err)
ngx.exit(500)
end

if not context[self].upstream then
ngx.log(ngx.WARN, "Upstream server not found for this request")
return errors.upstream_not_found(context.service)
Expand Down