From 4f2808e857e2f79aeb1ea0e04c5ae45d8dc10f07 Mon Sep 17 00:00:00 2001 From: wiaamm Date: Sun, 7 Dec 2025 10:05:02 +0200 Subject: [PATCH] move ngx.arg[1] to the beginning --- .../kong/plugins/open-appsec-waf-kong-plugin/handler.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua b/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua index f824690..e042a72 100755 --- a/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua +++ b/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua @@ -249,6 +249,8 @@ function NanoHandler.header_filter(conf) end function NanoHandler.body_filter(conf) + local chunk = ngx.arg[1] + local eof = ngx.arg[2] local ctx = kong.ctx.plugin if ctx.blocked or ctx.bypass_inspection then return @@ -258,9 +260,6 @@ function NanoHandler.body_filter(conf) local session_data = ctx.session_data if not session_id or not session_data or ctx.session_finalized then - -- Clear the chunk to release it from memory immediately - -- Without this, Kong holds chunks in memory causing OOM - ngx.arg[1] = nil return end @@ -273,7 +272,6 @@ function NanoHandler.body_filter(conf) local verdict, response, modifications = nano.end_inspection(session_id, session_data, nano.HttpChunkType.HTTP_RESPONSE_END) if modifications then - local chunk = ngx.arg[1] chunk = nano.handle_body_modifications(chunk, modifications, ctx.body_buffer_chunk or 0) ngx.arg[1] = chunk end @@ -300,9 +298,6 @@ function NanoHandler.body_filter(conf) return end - local chunk = ngx.arg[1] - local eof = ngx.arg[2] - if chunk and #chunk > 0 then ctx.body_buffer_chunk = ctx.body_buffer_chunk or 0 ctx.body_seen = true