115 Star 698 Fork 166

GVPiresty / Apache APISIX

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
uri-blocker.md 4.22 KB
一键复制 编辑 原始数据 按行查看 历史
title keywords description
uri-blocker
APISIX
Plugin
URI Blocker
This document contains information about the Apache APISIX uri-blocker Plugin.

Description

The uri-blocker Plugin intercepts user requests with a set of block_rules.

Attributes

Name Type Required Default Valid values Description
block_rules array[string] True List of regex filter rules. If the request URI hits any one of the rules, the response code is set to the rejected_code and the user request is terminated. For example, ["root.exe", "root.m+"].
rejected_code integer False 403 [200, ...] HTTP status code returned when the request URI hits any of the block_rules.
rejected_msg string False non-empty HTTP response body returned when the request URI hits any of the block_rules.
case_insensitive boolean False false When set to true, ignores the case when matching request URI.

Enabling the Plugin

The example below enables the uri-blocker Plugin on a specific Route:

curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/*",
    "plugins": {
        "uri-blocker": {
            "block_rules": ["root.exe", "root.m+"]
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    }
}'

Example usage

Once you have configured the Plugin as shown above, you can try accessing the file:

curl -i http://127.0.0.1:9080/root.exe?a=a
HTTP/1.1 403 Forbidden
Date: Wed, 17 Jun 2020 13:55:41 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 150
Connection: keep-alive
Server: APISIX web server

... ...

You can also set a rejected_msg and it will be added to the response body:

HTTP/1.1 403 Forbidden
Date: Wed, 17 Jun 2020 13:55:41 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 150
Connection: keep-alive
Server: APISIX web server

{"error_msg":"access is not allowed"}

Disable Plugin

To disable the uri-blocker Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/*",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    }
}'
Lua
1
https://gitee.com/iresty/apisix.git
git@gitee.com:iresty/apisix.git
iresty
apisix
Apache APISIX
master

搜索帮助