apisix icon indicating copy to clipboard operation
apisix copied to clipboard

feat:As a user, I don't think allowlist and denylist of ua-restriction can be enabled at the same time

Open 840963657 opened this issue 3 years ago • 5 comments

Description

I found other restriction plugin has a logic:Either one of whitelist or blacklist attribute must be specified。 But in ua-restriction, both allowlist and denylist can be used on their own. If User-Agent is neither on the allowlist nor the denylist , the processing logic is the same as that of the allowlist . So why do we still use the allowlist ?

840963657 avatar Jul 15 '22 00:07 840963657

Fair enough. But if we make allowlist and denylist exclusive, then this is a broken change. We need to evaluate it.

tokers avatar Jul 15 '22 00:07 tokers

if allowlist and denylist are both on, ua-restriction only uses allowlist, and User-Agents that are not in allowlist are rejected. How about this?

tzssangglass avatar Jul 15 '22 01:07 tzssangglass

Look like if the allowlist is matched, the denylist will be skipped? The match rule is via regex, so it is possible for a UA to match both allowlist and denylist.

spacewander avatar Jul 15 '22 06:07 spacewander

Another problem: If I only configure allowlist , User-Agent is not on allowlist will also be released.

this code in apisix/plugins/ua-restriction.lua(apisix 2.13)

` local MATCH_NONE = 0 local MATCH_ALLOW = 1 local MATCH_DENY = 2 ......

if match > MATCH_ALLOW then return 403, { message = conf.message } end `

I looked at the code, If User-Agent on allowlist, the value of match becomes MATCH_ALLOW. If User-Agent not on allowlist, the value of match is MATCH_NONE. In both cases, User-Agent will be released. So I think the allowlist is meaningless.

840963657 avatar Jul 15 '22 09:07 840963657

So we need an allowlist-only mode. When only allowlist is given, MATCH_NONE will be rejected. @840963657 Would you like to work on it?

spacewander avatar Jul 17 '22 12:07 spacewander

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Jul 04 '23 10:07 github-actions[bot]

I think the allowlist and denylist should be exclusive, it they exist at the same time, it is very difficult to understand

monkeyDluffy6017 avatar Jul 11 '23 02:07 monkeyDluffy6017

I think it could go either way:

  • Follow some sort of prioritization, e.g., allowlist over denylist. Match requests against each rule in order, and when any of the rules are satisfied, stop matching and either reject or pass them
  • Use exclusion mode to allow only one type of allowlist or denylist to be configured

The second is simpler and easier to understand. I'm not sure there is a need for the first way of this plugin.

bzp2010 avatar Jul 11 '23 03:07 bzp2010

@bzp2010 The first one looks meanless, if you set a allowlist, all you want is for the allowlist to pass, why do you set a blacklist at all? to block the one in the allowlist?

monkeyDluffy6017 avatar Jul 11 '23 03:07 monkeyDluffy6017

I think it could go either way:

  • Follow some sort of prioritization, e.g., allowlist over denylist. Match requests against each rule in order, and when any of the rules are satisfied, stop matching and either reject or pass them
  • Use exclusion mode to allow only one type of allowlist or denylist to be configured

The second is simpler and easier to understand. I'm not sure there is a need for the first way of this plugin.

1.I also agree with second way. 2.For first way, If the request not in both allowlist and denylist, what should we do? passing or rejecting seem not reasonable.

jiangfucheng avatar Jul 11 '23 03:07 jiangfucheng

I think we can work on this now

monkeyDluffy6017 avatar Jul 12 '23 17:07 monkeyDluffy6017

I think we can work on this now

Ok, I will raise a new PR for it.

jiangfucheng avatar Jul 13 '23 03:07 jiangfucheng