Recently deployed a couple of Django apps to my server. One of them is called aicoverlettercreator.com.
As usual when I deploy it to my server, I receive this message to my admin email account. These are all bots trying to ping my server, checking for vulnerabilities etc.
These emails are also extremely annoying. So I would like to block them.
Invalid HTTP_HOST header: 'www.twitch.tv:443'. You may need to add 'www.twitch.tv' to ALLOWED_HOSTS.
DisallowedHost at 443
Invalid HTTP_HOST header: 'www.twitch.tv:443'. You may need to add 'www.twitch.tv' to ALLOWED_HOSTS.
Request Method: CONNECT
Request URL: http://www.twitch.tv:443/443
Django Version: 4.2.2
Python Executable: /usr/local/bin/python
Python Version: 3.10.12
Python Path: ['/code', '/usr/local/bin', '/usr/local/lib/python310.zip', '/usr/local/lib/python3.10', '/usr/local/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/site-packages']
Server time: Fri, 21 Jul 2023 05:35:10 +0000
...
I’ve tried multiple ways to stop this:
Step 1: Django Settings
Here are the relevant Django settings;
# ...
ALLOWED_HOSTS = [
"aicoverlettercreator.com",
"localhost",
"127.0.0.1",
"the.ip.of.my.server",
]
CSRF_TRUSTED_ORIGINS = ["https://aicoverlettercreator.com"]
# ...
This is the normal config, nothing interesting. But kept receiving these emails.
Step 2: Blocking in my webserver
All my web apps are served in a single server using Caddy as a reverse proxy. After seeing multiple posts saying that I should tweak my nginx config, I blocked all hosts who’s header is not aicoverlettercreator.com
:
aicoverlettercreator.com {
@correctHeader {
header_regexp Host aicoverlettercreator\.com$
}
handle @correctHeader {
reverse_proxy :8888
}
@correctHTTPHost {
header HTTP_HOST aicoverlettercreator.com
}
handle @correctHTTPHost {
reverse_proxy :8888
}
}
Still receiving the emails.
Step 4: Blocking through Cloudflare
So nothing helped and I decided to block these requests also through Cloudflare:
But they keep coming!!!
A bit desperate at this point. What else can I do to stop these emails?