From 9bacadce4111937c67ec5ca1dbc1ebf03a112156 Mon Sep 17 00:00:00 2001 From: wiaamm Date: Sun, 14 Dec 2025 11:50:57 +0200 Subject: [PATCH] try content-length nil --- .../open-appsec-waf-kong-plugin/handler.lua | 16 ++++------------ 1 file changed, 4 insertions(+), 12 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 2548165..dbf7c4f 100755 --- a/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua +++ b/attachments/kong/plugins/open-appsec-waf-kong-plugin/handler.lua @@ -250,10 +250,9 @@ function NanoHandler.body_filter(conf) ctx.cleanup_needed = true if ctx.response_buffer and #ctx.response_buffer > 0 then local buffered_data = table.concat(ctx.response_buffer) - local original_content_length = tonumber(ngx.header["Content-Length"]) or #buffered_data - local total_diff = ctx.content_length_diff or 0 - ngx.header["Content-Length"] = original_content_length + total_diff + ngx.header["Content-Length"] = nil ngx.arg[1] = buffered_data + ctx.response_buffer = nil end return end @@ -264,7 +263,6 @@ function NanoHandler.body_filter(conf) if chunk and #chunk > 0 then ctx.body_buffer_chunk = ctx.body_buffer_chunk or 0 - ctx.content_length_diff = ctx.content_length_diff or 0 ctx.body_seen = true table.insert(ctx.response_buffer, chunk) @@ -272,10 +270,8 @@ function NanoHandler.body_filter(conf) local verdict, response, modifications = nano.send_body(session_id, session_data, chunk, nano.HttpChunkType.HTTP_RESPONSE_BODY) if modifications then - local original_length = #chunk chunk = nano.handle_body_modifications(chunk, modifications, ctx.body_buffer_chunk) local modified_length = #chunk - ctx.content_length_diff = ctx.content_length_diff + (modified_length - original_length) ctx.response_buffer[#ctx.response_buffer] = chunk end @@ -300,9 +296,7 @@ function NanoHandler.body_filter(conf) return else local buffered_data = table.concat(ctx.response_buffer) - local original_content_length = tonumber(ngx.header["Content-Length"]) or #buffered_data - local total_diff = ctx.content_length_diff or 0 - ngx.header["Content-Length"] = original_content_length + total_diff + ngx.header["Content-Length"] = nil ngx.arg[1] = buffered_data ctx.response_buffer = nil return @@ -340,9 +334,7 @@ function NanoHandler.body_filter(conf) if ctx.response_buffer and #ctx.response_buffer > 0 then local buffered_data = table.concat(ctx.response_buffer) - local original_content_length = tonumber(ngx.header["Content-Length"]) or #buffered_data - local total_diff = ctx.content_length_diff or 0 - ngx.header["Content-Length"] = original_content_length + total_diff + ngx.header["Content-Length"] = #buffered_data ngx.arg[1] = buffered_data else kong.log.debug("No buffered chunks to flush (empty response)")