Skip to content

Commit

Permalink
enable lua_check_client_abort
Browse files Browse the repository at this point in the history
Makes HTTP2 reset streams to be accounted and handled by apicast. Ref CVE-2023-44487
  • Loading branch information
eguzki committed Oct 31, 2023
1 parent 8143c1d commit 34ec61f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 34ec61f

Please sign in to comment.