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

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


The following commit(s) were added to refs/heads/master by this push:
     new e24fd85  change: blacklist $request_method in proxy-cache's cache key. 
(#1385)
e24fd85 is described below

commit e24fd851a39deb9b14e5ebb1ed65c56144ca450a
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Apr 2 08:55:48 2020 +0800

    change: blacklist $request_method in proxy-cache's cache key. (#1385)
    
    Close #1307
---
 apisix/plugins/proxy-cache.lua |  6 ++++++
 t/plugin/proxy-cache.t         | 45 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/apisix/plugins/proxy-cache.lua b/apisix/plugins/proxy-cache.lua
index 7b95aba..b9eacb2 100644
--- a/apisix/plugins/proxy-cache.lua
+++ b/apisix/plugins/proxy-cache.lua
@@ -108,6 +108,12 @@ function _M.check_schema(conf)
         return false, err
     end
 
+    for _, key in ipairs(conf.cache_key) do
+        if key == "$request_method" then
+            return false, "cache_key variable " .. key .. " unsupported"
+        end
+    end
+
     local found = false
     local local_conf = core.config.local_conf()
     if local_conf.apisix.proxy_cache then
diff --git a/t/plugin/proxy-cache.t b/t/plugin/proxy-cache.t
index dc49c95..6ded488 100644
--- a/t/plugin/proxy-cache.t
+++ b/t/plugin/proxy-cache.t
@@ -618,3 +618,48 @@ GET /t
 qr/cache_zone invalid_disk_cache not found/
 --- no_error_log
 [error]
+
+
+
+=== TEST 24: sanity check (invalid variable for cache_key)
+--- config
+       location /t {
+           content_by_lua_block {
+               local t = require("lib.test_admin").test
+               local code, body = t('/apisix/admin/routes/1',
+                    ngx.HTTP_PUT,
+                    [[{
+                        "plugins": {
+                            "proxy-cache": {
+                               "cache_zone": "disk_cache_one",
+                               "cache_key": ["$uri", "$request_method"],
+                               "cache_bypass": ["$arg_bypass"],
+                               "cache_method": ["GET"],
+                               "cache_http_status": [200],
+                               "hide_cache_headers": true,
+                               "no_cache": ["$arg_no_cache"]
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1985": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                   }]]
+                   )
+
+               if code >= 300 then
+                   ngx.status = code
+               end
+               ngx.say(body)
+           }
+       }
+--- request
+GET /t
+--- error_code: 400
+--- response_body eval
+qr/failed to check the configuration of plugin proxy-cache err: cache_key 
variable \$request_method unsupported/
+--- no_error_log
+[error]

Reply via email to