You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/04/29 13:08:22 UTC

[apisix] branch master updated: fix(response-rewrite): properly base64 process the nil and empty body (#4151)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 775c2e3  fix(response-rewrite): properly base64 process the nil and empty body (#4151)
775c2e3 is described below

commit 775c2e369d73257c97a8312fff2685a5d69faf1e
Author: Joey <ma...@apache.org>
AuthorDate: Thu Apr 29 21:08:12 2021 +0800

    fix(response-rewrite): properly base64 process the nil and empty body (#4151)
    
    Co-authored-by: Alex Zhang <to...@apache.org>
---
 apisix/plugins/response-rewrite.lua |  3 +++
 t/plugin/response-rewrite.t         | 47 +++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/apisix/plugins/response-rewrite.lua b/apisix/plugins/response-rewrite.lua
index 4959111..b415c7c 100644
--- a/apisix/plugins/response-rewrite.lua
+++ b/apisix/plugins/response-rewrite.lua
@@ -100,6 +100,9 @@ function _M.check_schema(conf)
     end
 
     if conf.body_base64 then
+        if not conf.body or #conf.body == 0 then
+            return false, 'invalid base64 content'
+        end
         local body = ngx.decode_base64(conf.body)
         if not body then
             return  false, 'invalid base64 content'
diff --git a/t/plugin/response-rewrite.t b/t/plugin/response-rewrite.t
index 18c02bc..d1f23a9 100644
--- a/t/plugin/response-rewrite.t
+++ b/t/plugin/response-rewrite.t
@@ -629,3 +629,50 @@ hello world
 200
 --- no_error_log
 [error]
+
+
+
+=== TEST 22: set an empty body with setting body_base64 to true
+--- config
+    location /t {
+        content_by_lua_block {
+            local plugin = require("apisix.plugins.response-rewrite")
+            local ok, err = plugin.check_schema({
+                            body = "",
+                            body_base64 = true
+            })
+            if not ok then
+                ngx.say(err)
+                return
+            end
+        }
+    }
+--- request
+GET /t
+--- response_body
+invalid base64 content
+--- no_error_log
+[error]
+
+
+
+=== TEST 23: set an nil body with setting body_base64 to true
+--- config
+    location /t {
+        content_by_lua_block {
+            local plugin = require("apisix.plugins.response-rewrite")
+            local ok, err = plugin.check_schema({
+                            body_base64 = true
+            })
+            if not ok then
+                ngx.say(err)
+                return
+            end
+        }
+    }
+--- request
+GET /t
+--- response_body
+invalid base64 content
+--- no_error_log
+[error]