Skip to content

Commit 05629bb

Browse files
authored
Merge branch 'internetstandards:main' into main
2 parents ab28c6f + 417597e commit 05629bb

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

checks/tasks/dispatcher.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def check_results(url, checks_registry, remote_addr, get_results=False) -> Probe
4444
If the task is not registered and the user has not passed the task limit,
4545
start the task.
4646
"""
47+
4748
url = url.lower()
4849
cache_id = redis_id.dom_task.id.format(url, checks_registry.name)
4950
cache_ttl = redis_id.dom_task.ttl
@@ -53,7 +54,8 @@ def check_results(url, checks_registry, remote_addr, get_results=False) -> Probe
5354
log.debug("No task found for task in cache. Creating a new redis task.")
5455
# Task is not yet available (not running AND not in cache)
5556
# Limit concurrent task launches per IP
56-
req_limit_id = redis_id.req_limit.id.format(remote_addr)
57+
# replace colons with dots for IPv6 addresses as colons are used as namespaces
58+
req_limit_id = redis_id.req_limit.id.format(remote_addr.replace(":", ".") if remote_addr else None)
5759
req_limit_ttl = redis_id.req_limit.ttl
5860
if user_limit_exceeded(req_limit_id):
5961
log.debug("User limit exceeded. Too many requests from this IP. Blocked.")

docker/compose.development.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ services:
1717
environment:
1818
- INTERNETNL_DOMAINNAME
1919

20-
app:
20+
webserver:
21+
build:
22+
context: ..
23+
dockerfile: docker/webserver.Dockerfile
24+
develop:
25+
watch:
26+
# auto rebuild/reload when config files change
27+
- path: ./webserver/
28+
action: rebuild
2129

30+
app:
2231
develop:
2332
watch:
2433
# auto rebuild/reload when CSS/JS changes

docker/webserver/nginx_templates/app.conf.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ server {
178178

179179
proxy_set_header REMOTE-USER $remote_user;
180180

181+
# forward client IP for rate limiting on tasks (see `redis_id.py` `req_limit`)
182+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
183+
181184
include /etc/nginx/conf.d/basic_auth.include;
182185
# set proxy_pass argument for 'app' container as variable, this way nginx doesn't fail when 'app' is unresolvable at startup
183186
set $app http://app:8080;
@@ -217,6 +220,8 @@ server {
217220
# pass host for Django's allowed_hosts
218221
proxy_set_header Host $host;
219222
proxy_set_header X-Forwarded-Proto $scheme;
223+
# forward client IP for rate limiting on tasks (see `redis_id.py` `req_limit`)
224+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
220225
# set proxy_pass argument for 'app' container as variable, this way nginx doesn't fail when 'app' is unresolvable at startup
221226
set $app http://app:8080;
222227
proxy_pass $app;

integration_tests/integration/test_website.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,20 @@ def test_ipv6_ns_with_bad_connectivity(page, app_url, unique_id):
7373

7474
# but some of them are not resolvable
7575
expect(page.get_by_text("Not all name servers that have an IPv6 address are reachable over IPv6."))
76+
77+
78+
def test_rate_limit(page, app_url, test_domain, docker_compose_exec):
79+
"""Test if correct rate limit keys are created when starting a test."""
80+
81+
test_domain = "www." + test_domain
82+
83+
page.goto(app_url)
84+
85+
page.locator("#web-url").fill(test_domain)
86+
page.locator("section.websitetest button").click()
87+
88+
rate_limit_redis_entry = docker_compose_exec("redis", "redis-cli keys dom:req_limit:*").decode("utf8").strip()
89+
assert rate_limit_redis_entry, "there should be a redis entry for rate limiting"
90+
assert not rate_limit_redis_entry.endswith(
91+
"None"
92+
), "there should be no rate limit key created with `None` as IP address"

0 commit comments

Comments
 (0)