Skip to content

Commit 7c02262

Browse files
committed
Skip user blocking when bypassed IP
1 parent 5a52c6b commit 7c02262

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

aikido_zen/middleware/init_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ def test_with_context_with_cache():
5555
assert thread_cache.stats.rate_limited_hits == 0
5656

5757

58+
def test_bypassed_ip_skips_user_blocking():
59+
test_utils.generate_and_set_context(user={"id": "123"}, ip="1.2.3.4")
60+
thread_cache = get_cache()
61+
thread_cache.config.blocked_uids = ["123"]
62+
thread_cache.config.set_bypassed_ips(["1.2.3.4"])
63+
64+
assert should_block_request() == {"block": False}
65+
66+
5867
def test_cache_comms_with_endpoints():
5968
test_utils.generate_and_set_context(user={"id": "456"}, route="/posts/:id")
6069
set_rate_limit_group("my_group")

aikido_zen/middleware/should_block_request.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def should_block_request():
3232
context.executed_middleware = True
3333
context.set_as_current_context()
3434

35+
# Bypassed IPs skip user blocking and rate limiting
36+
if cache.is_bypassed_ip(context.remote_address):
37+
return {"block": False}
38+
3539
# User blocking allows customers to easily take action when attacks are coming from specific accounts
3640
if context.user and cache.is_user_blocked(context.user["id"]):
3741
return {"block": True, "type": "blocked", "trigger": "user"}

0 commit comments

Comments
 (0)