1 Star 0 Fork 166

南风不竞 / Apache APISIX

forked from iresty / Apache APISIX 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
referer-restriction.md 3.24 KB
一键复制 编辑 原始数据 按行查看 历史
John Bampton 提交于 2021-01-03 13:26 . docs: lint Markdown files (#3177)

Summary

Name

The referer-restriction can restrict access to a Service or a Route by whitelisting request header Referrers.

Attributes

Name Type Requirement Default Valid Description
whitelist array[string] required List of hostname to whitelist. The hostname can be started with * as a wildcard
bypass_missing boolean optional false Whether to bypass the check when the Referer header is missing or malformed

How To Enable

Creates a route or service object, and enable plugin referer-restriction.

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/index.html",
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:1980": 1
        }
    },
    "plugins": {
        "referer-restriction": {
            "bypass_missing": true,
            "whitelist": [
                "xx.com",
                "*.xx.com"
            ]
        }
    }
}'

Test Plugin

Request with Referer: http://xx.com/x:

$ curl http://127.0.0.1:9080/index.html -H 'Referer: http://xx.com/x'
HTTP/1.1 200 OK
...

Request with Referer: http://yy.com/x:

$ curl http://127.0.0.1:9080/index.html -H 'Referer: http://yy.com/x'
HTTP/1.1 403 Forbidden
...
{"message":"Your referer host is not allowed"}

Request without Referer:

$ curl http://127.0.0.1:9080/index.html
HTTP/1.1 200 OK
...

Disable Plugin

When you want to disable the referer-restriction plugin, it is very simple, you can delete the corresponding json configuration in the plugin configuration, no need to restart the service, it will take effect immediately:

$ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d value='
{
    "uri": "/index.html",
    "plugins": {},
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'

The referer-restriction plugin has been disabled now. It works for other plugins.

Lua
1
https://gitee.com/limengcanyu/apisix.git
git@gitee.com:limengcanyu/apisix.git
limengcanyu
apisix
Apache APISIX
master

搜索帮助